我想创建一个“简单”的方式来问一个人他们想要找到什么形状的区域。然后根据他们的输入找出形状的区域。我正在使用Python 2.7.3。以下是我迄今为止:if-statement取决于输入
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. ")
你所拥有的一切运作正常。只是像你这样的一些不必要的变量不需要'c =“''和'r =”“',你应该在你的'input'的末尾加上'.lower()',这样大写的响应仍然被接受 – 2013-04-25 14:22:51
非常感谢你!现在就像魅力一样。 – 2013-04-25 15:05:13
我只是不明白为什么我收到-1。 – 2013-11-13 15:44:50