Python 取决于输入的if语句

Python 取决于输入的if语句,python,input,Python,Input,我试图创建一个“简单”的方法来询问一个人他们希望找到的区域是什么形状。然后根据输入找到形状的区域。我正在使用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 yo

我试图创建一个“简单”的方法来询问一个人他们希望找到的区域是什么形状。然后根据输入找到形状的区域。我正在使用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. ")

一定要养成一种习惯,不只是发布代码,还要给出一个句子或两个解释。@Dukeling解释在代码的注释中,有些括号可以从代码中删除。并不是说把它们放在那里是错误的,只是多余的。你的一切都运转良好。只需要几个不必要的变量,比如你不需要
c=“”
r=“”
,你应该在
输入的末尾添加
.lower()
,这样大写字母的响应仍然可以接受谢谢!我现在很有魅力。我只是不明白为什么我得到了-1分。
from math import pi
# use raw input (raw_input()) for the inputs... input() is essentially eval(input())
# this is how i would ask for input for a simple problem like this
x = (raw_input("Do you have a [r]ectangle or a [c]ircle? ")) # Answer with r or c
# use .lower() to allow upper or lowercase
if x.lower() == "r":
    l = (int(raw_input("What is the length of your rectangle? ")))
    w = (int(raw_input("What is the width of your rectangle? ")))
    print( l * w )
elif x.lower() == "c":
    r = (int(raw_input("What is the radius of your circle? ")))
    print( r ** 2 * pi)
else:
    print("You didn't enter r or c.")