PDA

View Full Version : What this?


ChefNinja
07-19-2002, 08:03 PM
Oh, thats right.. it's my first python program :D


def sq_area(length):
area = length*length
return area

def circ_area(radius):
area = 3.14*radius**2
return area

def menu():
print "------------------"
print "1. Area of square"
print "2. Area of circle"
print "9. Quit"

ui = "0"
while ui != 9:
if ui == 1:
length = input("Enter the length: ")
print sq_area(length)
elif ui == 2:
radius = input("Enter the radius: ")
print circ_area(radius)
elif ui != 9:
menu()
ui = input("What would you like to do? ")
print "Press Ctrl+C to Quit"


w00t! :)

gufmn
07-19-2002, 08:34 PM
schweet! don't forget to call the menu() function. and you might want to throw in an "else" statement just in case some idiot selects 3 or X or something else not listed.

ChefNinja
07-19-2002, 08:54 PM
There is one, if someone inputs something other than what is listed, the menu comes up again

err, if you put in a letter you get an error :(


Traceback (most recent call last):
File "C:\Python22\area.py", line 25, in ?
ui = input("What would you like to do? ")
File "<string>", line 0, in ?
NameError: name 'x' is not defined

gufmn
07-19-2002, 09:32 PM
else:
print "You are an idiot. That is not a choice. You must now start over"
menu()

Strike
07-19-2002, 11:00 PM
If you want pi, there's math.pi ...

ChefNinja
07-20-2002, 02:35 AM
Shh, I'm following a tutorial here :P

It says use 3.14, I use 3.14 :)

ChefNinja
07-21-2002, 11:22 PM
http://home.attbi.com/~andro/python/


yay :)

gufmn
07-22-2002, 05:03 PM
Originally posted by ChefNinja
Shh, I'm following a tutorial here :P

It says use 3.14, I use 3.14 :)



Which tutorial are you using?