Python noob here。我试图添加一组在'if'语句中定义的输入变量,并且每当我尝试查找总和时,它将只显示内联值。例如,当A,B,c和d等于5,周长= 555 ...如何在Python中添加变量?
shape = raw_input("Is the plot a (q) quadrilateral or (t) triangle?")
if shape.lower() == "q":
a = raw_input("What is the length in feet of side 'a'?")
b = raw_input("What is the length in feet of side 'b'?")
c = raw_input("What is the length in feet of side 'c'?")
d = raw_input("What is the length in feet of side 'd'?")
elif shape.lower() == "t":
a = raw_input("What is the length in feet of side 'a'?")
b = raw_input("What is the length in feet of side 'b'?")
c = raw_input("What is the length in feet of side 'c'?")
else:
print "Please enter 'q' for quadrilateral or 't' for triangle."
if shape.lower() == "q":
perimeter = a + b + c + d
elif shape.lower() == "t":
perimeter = a + b + c
else:
print "Please make sure you enter numbers only."
print perimeter
http://www.programmingforums.org/thread22164.html – 2013-05-01 06:54:21
你缺少一个用于加法的int()。 – squiguy 2013-05-01 06:54:50