Python HandsOn HackerRank Solved

  1. ) Using intMath Operations

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 7 Side Radius Sample

Output Area of Square is 25

Volume of Cube is 125

Area of Circle is 153.86

Volume of Sphere is 1436.63

SOLUTION :

#!/bin/python3

import math
import os
import random
import re
import sys

import math
#
# 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
    print('Area of Square is',Side*Side)
    print('Volume of Cube is',Side*Side*Side)
    ar=3.14*Radius*Radius
    vol=(4*3.14*Radius*Radius*Radius)/3
    print('Area of Circle is',round(ar,2))
    print('Volume of Sphere is',round(vol,2))

if __name__ == '__main__':

2 ) Handson -Python -Using Float1

Sanjay is trying to help Vijay to find area of triangle. But for some reasons he is trying to find some relation between area and pi.

#!/bin/python3

import math
import os
import random
import re
import sys


import math
#
# Complete the 'triangle' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
#  1. FLOAT n1
#  2. FLOAT n2
#  3. INTEGER n3
#

def triangle(n1, n2, n3):
    # Write your code here
    area =(n1*n2)/2
    a2 =round(math.pi,n3)
    return(round(area,n3),a2)

if __name__ == '__main__':

3) Using float 2

Rakul started learning Python3 to participate in upcoming “CodeChamp”, Write the function definition for function “Float_fun”

#!/bin/python3

import math
import os
import random
import re
import sys


import math
#
# Complete the 'Float_fun' function below.
#
# The function accepts following parameters:
#  1. FLOAT f1
#  2. FLOAT f2
#  3. INTEGER Power
#

def Float_fun(f1, f2, Power):
    # Write your code here
    print('#Add')
    print(f1+f2)
    print('#Subtract')
    print(f1-f2)
    print('#Multiply')
    print(f1*f2)
    print('#Divide')
    print(f2/f1)
    print('#Remainder')
    print(f1%f2)
    print('#To_The_Power_Of')
    ans=math.pow(f1,Power)
    print(ans)
    print('#Round')
    print(round(ans,4))
    
if __name__ == '__main__':

4)Using Int Operations :

Define a function called ‘find’ which takes three parameters. Print the output of comparison of numbers in the parameters based on certain conditions

#!/bin/python3

import math
import os
import random
import re
import sys


#
# Complete the 'find' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
#  1. INTEGER num1
#  2. INTEGER num2
#  3. INTEGER num3
#

def find(num1, num2, num3):
    a=(num1<num2 and num2>=num3)
    b=(num1>num2 and num2<=num3)
    c=(num3==num1 and num1!=num2)
    print(a,b,c)
    # Write your code here

if __name__ == '__main__':
Prev Post

Leave a Reply

Your email address will not be published. Required fields are marked *