I am new to the forums and I am creating a Area Calculator for extra credit for a class I am in, but I am running into some problems. I have the program coded out the way it needs to operate I just can't seem to get it to loop after I have processed one selection. Could anyone please help me out with this?? I would really appreciate it.

Here is a copy of the code that I have so far.

# Area calculation program

print "Area Calculation Program"
print "1. Triangle"
print "2. Circle"
print "3. Rectangle"
print "4. Quit"

# Get the user’s choice:
shape = input("Please select a number 1-4: ")

# Calculate the area:
if shape == 1:
    height = input("Please enter the height: ")
    width = input("Please enter the width of the base: ")
    area = 0.5*(height*width)
    print "The area is", area   
if shape == 2:
    radius = input("Please enter the radius: ")
    area = 3.14159*(radius**2)
    print "The are is", area
if shape == 3:
    height = input("Please enter the height: ")
    width = input("Please enter the width: ")
    area = height*width
    print "The area is", area

You need a loop that checks if the user has selected option 4 or rather check that the user hasn't selected 4 in order to continue looping.

Give it a try and come back with any questions.

Also, use raw_input, not input. input will evaluate the users input as Python code. Google will give you a little more info or you can ask questions here.

Here's a way:

shape = 0
while shape != 4:
    # Your existing code can go here

Just slap that -blam- into a while loop and you've got a class 5 repeater.

This article has been dead for over six months. Start a new discussion instead.