我正在用python开发一个面积计算器,一切似乎都很好,......直到我开始计算圆的周长......
谁能指出我正确的方向?
import math
from math import pi
menu = """
Pick a shape(1-3):
1) Square (area)
2) Rectangle (area)
3) Circle (area)
4) Square (perimeter)
5) Rectangle (perimeter)
6) Circle (perimeter)
7) Quit
"""
shape = int(input(menu))
while shape != 7:
if shape == 1:
length = float(input("Length: "))
print( "Area of square = ", length ** 2 )
elif shape == 2:
length = float(input("Length: "))
width = float(input("Width: "))
print( "Area of rectangle = ", length * width )
elif shape == 3:
area = float(input("Radius: "))
circumference = float(input("radius: "))
print( "Area of Circle = ", pi*radius**2 )
elif shape == 4:
length = float(input("Length: "))
print( "Perimeter of square = ", length *4 )
elif shape == 5:
length = float(input("Length: "))
width = float(input("Width: "))
print( "Perimeter of rectangle = ", (length*2) + (width*2))
elif shape == 6:
circumference = float(input("radius: "))
print( "Perimeter of Circle = ", 2*pi*radius)
shape = int(input(menu))