[Tutor] Function problem

Eri Mendz jerimed at myrealbox.com
Sat Nov 6 06:54:28 CET 2004


On Fri, 5 Nov 2004, Danny Yoo wrote:

> 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!

Hi Danny,

I tried learning C++ few years back but didnt go too far. So does Perl
and shell scripting, all on my own pace. Dunno if all mixed up in my
head.  Drop them as in not use break all together? I look over my code
again without the break in the temperature conversion.

-- 
Regards,
Eri Mendz
Using PC-Pine 4.61



More information about the Tutor mailing list