我正在尝试创建一种“简单”的方式来询问一个人他们想找到什么形状的区域。然后根据他们的输入找到形状的区域。我正在使用 Python 2.7.3。这是我到目前为止所拥有的:
from math import pi
c = ""
r = ""
x = (input("Do you have a [r]ectangle or a [c]ircle? ")) # Answer with r or c
if x == "r":
l = (int(input("What is the length of your rectangle? ")))
w = (int(input("What is the width of your rectangle? ")))
print( l * w )
elif x == "c":
r = (int(input("What is the radius of your circle? ")))
print( r ** 2 * pi)
else:
print("Please enter request in lower case. ")