Hi, I was trying to write a Python area calculator that repeats, and then ends when you want it to. This is the code:
keep_going = True
while(keep_going == True):
print " "
print "----------------------------"
print "Hello, I'm a simple calculator coded by Max Farr. I can tell you the area of a square, a rectangle, a triangle, or a circle."
print "Which would you like to see?"
print "----------------------------"
print
print "1 Square"
print "2 Rectangle"
print "3 Triangle"
print "4 Circle"
shape = input ("> ")
if shape == 1:
lengthwidth = input ("What is the length of a side of the square?")
area = lengthwidth*2
print "The area is", area
if shape == 2:
length = input ("What is the length of the rectangle?")
width = input ("What is the width of the rectangle?")
area = length*width
print "The area is", area
if shape == 3:
base = input ("What is the length of the base of the triangle?")
height = input ("What is the height of the triangle?")
area = base*height/2
print "The area is", area
else:
radius = input ("What is the radius of the circle?")
area = radius*radius*3.14159265358
print "The area is approximately", area
print "Alright!"
goagain = input("Do you want to run again? answer yes or no")
if goagain == yes:
keep_going = True
print "Cool!"
else:
keep_going = False
print "Goodbye!"
When I run it, and it comes to the part where it asks you if you want to go again, and I answer yes or no, it gives me this:
Traceback (most recent call last):
File "C:/Python27/[the file name]", line 41, in <module>
goagain = input("Do you want to run again? answer yes or no")
File "<string>", line 1, in <module>
NameError: name 'no [b](or yes, if I answer yes)[/b]' is not defined
Also, when I calculate the area of a square or rectangle, it then asks me what "the radius of the circle is". Then it calculates the circle. o_o Basically, it goes into the circle calculator. o_o
Can you guys help me with these two issues?