Skip to main content

Hacker Rank using int math opeartor

Area & Volume

 

Sunil had an assignment on "Areas & Volumes" given by his Mathematics Teacher.He was given

1.'Side',from which he have to find

- Area of Square &

- Volume of Cube

2.'Radius' ,from which he have to find

- Area of Circle &

- Volume of Sphere

3."pi" equals to 3.14

 

Write the function definition for the function ''Integer_Math" which takes two arguments 'Side' and 'Radius'

 

Print the Areas and Volumes as per the Sample Test Case below.

 

Input Format for Custom Testing:

# In the first line, value for 'Side'

# In the second line, value for 'Radius'

 

Note:

-The outputs must be rounded off to two decimal places
-Use round() for rounding off
    -Example : round(123.45555, 2) is 123.46

 

Sample Test Case 1:

 

Sample Input

STDIN      Function parameter
-----      ------------------
5      →   Side
7      →   Radius

 

Sample Output

Area of Square is 25
Volume of Cube is 125
Area of Circle is 153.86
Volume of Sphere is 1436.03

 




#!/bin/python3

import math
import os
import random
import re
import sys



#
# Complete the 'Integer_Math' function below.
#
# The function accepts following parameters:
#  1. INTEGER Side
#  2. INTEGER Radius
#

def Integer_Math(Side, Radius):
    # Write your code here

    pi = 3.14
    area = Side * Side
    print(f'Area of Square is {area}')
    volume = Side*Side*Side
    print(f'Volume of Cube is {volume}')
    area_circle = round((pi * (Radius*Radius)),2)
    print(f'Area of Circle is {area_circle}')
    volume_sphere = round((4/3 * pi * (Radius**3)),2)
    print(f'Volume of Sphere is {volume_sphere}')

if __name__ == '__main__':
    Side = int(input().strip())

    Radius = int(input().strip())

    Integer_Math(Side, Radius)

Comments

  1. def Integer_Math(Side, Radius):
    # Write your code here
    print('Area of Square is',round(Side**2,2))
    print('Volume of Cube is',round(Side**3,2))
    print('Area of Circle is',round(3.14*(Radius**2),2))
    print('Volume of Square is',round(4/3*(3.14*(Radius**3)),2))

    ReplyDelete

Post a Comment

Popular posts from this blog

Python Hacker Rank Question and Answer -- Hands-on - Range

Python - Range1   Define a function called ` rangefunction ` which takes three parameters . The first parameter is ` startvalue ` , the next parameter is ` endvalue` and the last parameter is 'stepvalue' .   The function definition code stub is given in the editor. Generate the squares of numbers from ` startvalue ` to ` endvalue ` using range   based on condition given below:   Print the values which must be separated by tab spaces. Note: startvalue and endvalue both are inclusive in the range.    Constraints 1 ≤ startvalue Input Format for Custom Testing   In the first line  startvalue given In the second line endvalue given In the second line stepvalue given     Sample Case 0   Sample Input STDIN      Function -----      -------- 2       → startvalue = 2 9 → endvalue = 9 2 → ...

Python Hacker Rank Question and Answer -- Hands-on - Namespaces

  Python - Namespaces Write the function definition for the function  ' Assign ' to assign the different types of variables in its parameters to new variables. Parameters: 1.An INTEGER in the variable ' i ' 2.A FLOAT in the variable ' f ' 3.A STRING in the variable ' s ' 4.A BOOLEAN in the variable ' b '   New Variables to be assigned with : 1.An INTEGER in the variable ' w ' 2.A FLOAT in the variable ' x ' 3.A STRING in the variable ' y ' 4.A BOOLEAN in the variable ' z '   Assign the parameter variables  Respectively . and Print these in the following order: 1.w 2.x 3.y 4.z 5.Display all the objects defined in the current namespace by using the 'dir' function   Input Format for Custom Testing: # In the first line, value for ' i ' # In the second line, value for ' f ' # In the third line, value for ' s ' # In the fourth line, value for ' b '   Sample Test Case 1:   Sampl...

Python Hacker Rank Question and Answer

Python Question And Answers  Question : Python - Get Additional Info   Define a function called ` docstring `  which takes one parameter .  The  parameter 'function-name' is a  Python  built-in function  name.   The function definition code stub is given in the editor. Generate a  Docstring of the input function  based on the condition given below:   The Docstring must give the maximum information about the function.     Constraints Input must be a string. Input Format Format for Custom Testing   In the input, any python built-in function is   given as a string.     Sample Case 0   Sample Input STDIN      Function -----      -------- print   → functionname = print Sample Output: Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream...