building a small calculator

aleksander.helgaker at gmail.com aleksander.helgaker at gmail.com
Wed Apr 20 08:18:17 EDT 2005


I'm learning to program python on my Mac and I'd like some help. I
followed a tutorial which showed how to make a calculator for working
out the area of a shape. E.g. the area of a circal is pi*r*r.

To practice a bit I thought I'd make the program more advanced but I'm
already having difficoulties. Here is what I have so far.

<code>
# Area calculation program
print "Welcome to the Area calculation program"
print "---------------------------------------"
print

# Print out the menu:
print "Please select a shape:"
print "1 Rectangle"
print "2 Circle"
print "3 Square"

# Get the user's choice:
shape = input("> ")

# Calculate the area:
if shape == 1:
	height = input("Please enter the height: ")
	width = input("Please enter the width: ")
	area = height*width
	print "The area is", area
elif shape == 2:
	radius = input("Please enter the radius: ")
	area = 3.14*(radius**2)
	print "The area is", area
else:
	length = input("Please input the length: ")
	area = length**2
	print "The area is", area
</code>

Now once the user has select a shape and typed in the lengths required,
the result is printed and the program quits. What I want to do is make
the program display the result and then make it wait for the user to
press return (or something like that) after which the screen will be
cleared and they'll be back at the main menu.

Also I would like to add option nr 4 to the menu and make that the quit
command, but what command does python have to stop a program? I tried
end but that did not work.




More information about the Python-list mailing list