Reputation: 15
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
How can I program the code to say that a
is the area and p
is the perimeter?
Upvotes: 1
Views: 1315
Reputation: 32189
You are doing your checks wrong. In python a =
means assignment whereas ==
is a test for equality. Try this instead:
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
Upvotes: 1
Reputation: 19264
This is odd, you cannot check to see if raw_input()
is something. And also, it is ==
to test for equality, =
is to assign. Here is what you want:
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
Upvotes: 2