Python - Usage imports
Define a function called `calc` which takes one parameter. The 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:
- Radius:
- 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:
#!/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
from math import pi
# calculate radius of the circle
r = (c/(2*pi))
area = (pi * r**2)
r = round(r,2)
area = round(area,2)
return (r,area)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
c = int(input().strip())
result = calc(c)
fptr.write(str(result) + '\n')
fptr.close()
Comments
Post a Comment