I'm trying to write a program that prints a 3-column table showing the circumference and area of ten circles of a specified random radius. The low and high values for the range of random radii are specified by user inputs in main. The main function should then use these high and low values and the random module in a loop to generate random integers and execute the custom function with the random integers as radii.
I keep getting an error that radius is not defined, but I guess I'm not understanding why. And if I break up the function in a module I can get it to print 1 line of data, but not 10.
import math
import random
import circles
# MAIN FUNCTION
# Input = None
# Output = radius
# Prompt user for a low integer
# Prompt user for a high integer
def main():
low = int(input('Enter a low integer for the random radii:'))
high = int(input('Enter a high integer for the random radii:'))
for count in range(10):
radius = random.randint(low, high)
# getCircumf
# Calculates the circumference of a circle
#
# inputs: radius
# output: circumference
#
def getCircles(radius):
circumf = 2 * math.pi * radius
area = math.pi * radius ** 2
return circumf
return area
print('Radius Circumference Area')
print('------ ------------- ----')
print(format(radius, '6.1f',), format(circumf, '12.3f'), format(area, '11.2f'))
Aucun commentaire:
Enregistrer un commentaire