Small program trouble WAS Re: Small proram troble
Tim Hammerquist
tim at vegeta.ath.cx
Mon Sep 3 21:14:22 EDT 2001
Me parece que Rob <uselesspython at yahoo.com> dijo:
> Ignacio Vazquez-Abrams wrote:
> And here's my fixed version of the fixed version:
[ snippage ]
> choice = 0
Why even initialize it? You never modify it, and it's only used inside
the while: loop.
[ snippage ]
> while choice != 6:
Not much chance of this happening. Only in Perl is "6" == 6. <wink>
How bout this:
def print_options():
print """Options:
1 Print Options
2 Add numbers
3 Subtract numbers
4 Multiply number
5 Divide number
6 Exit
""" # easier to read, and prints prettier, too! <wink>
print_options()
while 1: # this is what happens anyway
choice = raw_input("What would thou like to do? ")
if choice == "6": # get it out of the way
break # sometimes sys.exit() ~ GOTO
elif choice == "1":
print_options()
elif choice == "2":
add = input("What number would you like to add? ")
add2 = input("What other number do you want to add? ")
print "The awnser is", add + add2
elif choice == "3":
sub = input("What number do you want to subtract? ")
sub2 = input("What 2nd number do you want to subtract? ")
print "Your awnser is,", sub + sub2
elif choice == "4":
mul = input("What number do you want to multiply? ")
mul2 = input("What 2nd number do you want to multiply? ")
print "Your multiplicated number is", mul * mul2
elif choice == "5":
div = input("What is your dividend? ")
div2 = input("What is your numerator? ")
print "Your awnser is", div/div2
print "thanks for using my program"
--
You are alive. So live.
-- Morpheus, The Sandman
More information about the Python-list
mailing list