我在蟒蛇的面積計算器工作的周長,一切似乎確定,...直到我去計算圓的周長...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))
你不指定任何地方方圓... –