Search This Blog

Handson Python Usage imports Hacker Rank question and answer; Digital: Python 3 Programming_FP; Course ID: 55193

Python - Usage imports

Define a function called `calc` which takes one parameterThe parameter 'c' is an integer which is the circumference of the circle. The function definition code stub is given in the editor. Find the radius and Area of the circle using math module based on condition given below:

 

  • Formula for
    • Radius: 
    • Area:  
  • Return both Radius and Area. 
    • The values must be rounded off to 2 positions.

Constraints

  • input must be an integer.

Input Format Format for Custom Testing

 

  • In the first line c given.

Sample Case 0

 

Sample Input

STDIN      Function
-----      --------
8       →  c = 8

Sample Output

(1.27, 5.09)  

Explanation

  • With 8 as input, Radius and Area are calculated and returned


Answer:
    Image Reference:
#!/bin/python3

import math
import os
import random
import re
import sys
#
# Complete the 'calc' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER c as parameter.
#
def calc(c):
    # Write your code here
    r = c/(2*math.pi)
    a = math.pi * r**2  
    r = round(r,2)
    a = round(a,2)
    return(r,a)
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    c = int(input().strip())
    result = calc(c)
    fptr.write(str(result) + '\n')
    fptr.close()



No comments:

Post a Comment

If you have any doubts, Please let us know.