print "This is to find the area or perimeter of a rectangle "
print "Do you want to find the area(a) or perimeter(p) of your rectangle?"
a= raw_input(" I want to find the ")
if raw_input = (a)
print "What is the length of the rectangle?"
b = int(raw_input("The length of the rectangle is "))
print "What is the width of the rectangle?"
c = int(raw_input("The width of the rectangle is "))
d = (2 * b) + (2 * c)
print d
if raw_input = (p)
print "Got it. What is the length of your rectangle?"
x = int(raw_input("The length of the rectangle is "))
print "What is the width of your rectangle?"
y = int(raw_input("The width of the rectangle is "))
z = x * y
print z
如何编写代码来说明a
是区域而p
是周边?
答案 0 :(得分:2)
这很奇怪,你无法检查是否raw_input()
是什么。而且,测试相等性是==
,=
是要分配。这是你想要的:
print "This is to find the area or perimeter of a rectangle "
print "Do you want to find the area(a) or perimeter(p) of your rectangle?"
a= raw_input(" I want to find the ")
if a=='p':
print "What is the length of the rectangle?"
b = int(raw_input("The length of the rectangle is "))
print "What is the width of the rectangle?"
c = int(raw_input("THe width of the rectangle is "))
d = (2 * b) + (2 * c)
print d
elif a=='a':
print "Got it. What is the length of your rectangle?"
x = int(raw_input("The length of the rectangle is "))
print "What is the width of your rectangle?"
y = int(raw_input("The width of the rectangle is "))
z = x * y
print z
答案 1 :(得分:1)
你的检查错了。在python中,=
表示赋值,而==
是对相等性的测试。试试这个:
print "This is to find the area or perimeter of a rectangle "
print "Do you want to find the area(a) or perimeter(p) of your rectangle?"
a= raw_input(" I want to find the ")
if a=='a':
print "What is the length of the rectangle?"
b = int(raw_input("The length of the rectangle is "))
print "What is the width of the rectangle?"
c = int(raw_input("THe width of the rectangle is "))
d = b*c
print d
elif a=='p':
print "Got it. What is the length of your rectangle?"
x = int(raw_input("The length of the rectangle is "))
print "What is the width of your rectangle?"
y = int(raw_input("The width of the rectangle is "))
z = 2*x+2*y
print z