[Tutor] Function problem
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Fri Nov 5 21:55:19 CET 2004
On Fri, 5 Nov 2004, Eri Mendz wrote:
> The problem of my script below is in the proceed function: if Y is
> selected, instead of staying in the option menu, the program just shows
> the option menu then exits.
Hi Eri,
Ah! Check the 'break' statements in the main loop of the program:
> choice = raw_input("select options: ")
> if choice == 'c' or choice == 'C':
> try:
> getftemp = int(raw_input("enter fahrenheit temperature: "))
> print "temp in C is: ", c2f(getftemp)
> proceed()
> except ValueError:
> print "error: not a valid input!"
> break
> elif choice == 'f' or choice == 'F':
> try:
> getctemp = int(raw_input("enter centigrade temperature: "))
> print "temp in F is: ", f2c(getctemp)
> proceed()
> except ValueError:
> print "error: not a valid input!"
> break
The breaks cause us to jump out of the while loop if either temperature
choice gets selected.
I'm guessing that you're using a C switch statement idiom. But since that
idiom isn't applicable in Python, you should just drop them.
Good luck to you!
More information about the Tutor
mailing list