j = True
while j == True:
area = raw_input("Elije la figura geometrica para calcular su area
\nCuadrado=1 \nTriangulo=2 \nCirculo=3\n")
if area == 1 :
acuadrado()
问题在于该区域。它是语法中的东西吗?
答案 0 :(得分:0)
raw_input
返回一个"字符串"用户输入的表示。您想要对输入进行数值比较,因此您需要在执行比较之前将area
变量强制转换为整数(int
)。如下所示:
area = int(raw_input("Elije la figura geometrica..")
或
area = raw_input("Elije ...")
area = int(area)
然后您可以比较int
值:
if area == 1 :
acuadrado()
等...
这样的事情可能会帮助你相处:
def acuadrado():
print 'acuadrado'
def atriangulo():
print 'atriangulo'
def acirculo():
print 'acirculo'
j = True
while j == True:
area = raw_input("Elije la figura geometrica para calcular su area \nCuadrado=1 \nTriangulo=2 \nCirculo=3\n")
area = int(area)
if area == 1 :
acuadrado()
elif area == 2:
atriangulo()
elif area == 3:
acirculo()
else:
print 'nada'
j = False
另见How can I convert a string to an int in Python?
希望有所帮助。