[Tutor] Error checking - very basic question

Andrei project5 at redrival.net
Sun Sep 25 13:05:35 CEST 2005

Garry Rowberry wrote:
> def ask_dau_version():
>     """Determine the product issue of the DAU."""
>     dau_version = None
>     while dau_version not in ("2.8", "2.1"):
>         dau_version = raw_input("\n\tIs the DAU a version 2.1 or 2.8, please
> enter only 2.1 or 2.8 ")
>         print"\n\t\aError! - please enter only 2.1 or 2.8."
>     else:
>         print""
>     return dau_version
> I can see why it isn't working, the error message is in the wrong place, but
> I can't see a simple way around it (wood for the trees)

How about using a "while True" loop that you break out of only when a 
correct value has been identified:

     while True:
         dau_version = raw_input('blabla')
         if dau_version in ("2.8", "2.1"):
             print "Error"



Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V 
ernq gur yvfg, fb gurer'f ab arrq gb PP.

More information about the Tutor mailing list