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

Recommended Answers

All 5 Replies

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 does not work in the latest python


This post has no text-based content.

@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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.