Nov-10-2019, 03:07 AM
I'm writing a practice script to prompt the user to input "Area" or "Radius", then input the area or radius of a circle to calculate the other.
I wanted to use functions to do it.
Here's what I've got so far:
I wanted to use functions to do it.
Here's what I've got so far:
import math
from math import pi
def area():
radius = float(input("To calculate the Area enter the Radius of the circle: "))
area = float(pi)*pow(radius,2)
print("The Area is " + str(area))
def radius():
area = float(input("To calculate the Radius enter the Area of the circle: "))/pi
radius = str(math.sqrt(area))
print("The Radius is " + radius)
choice = {'Radius': radius, 'Area': area}
action = input("Calculate Area or Radius? ")
action = action.capitalize()
choice[action]()Is there a superior way to do this? Are there any lines I can cut or condense?
