0

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
print "1. Triangle"
print "2. Circle"
print "3. Rectangle"
print "4. Quit"
print

# 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
6
Contributors
5
Replies
24
Views
8 Years
Discussion Span
Last Post by Gribouillis
0

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.

0

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.

1

@prince_16 Many python snippets written 7 years ago were written in python 2. That's why they don't work out of the box in python 3. However they can be easily adapted to python 3 with minor changes or with the help of the 2to3 tool.

It is not useful to revive old threads like this. Start your own thread instead with the code you're working on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.