[Tutor] Input handling?

Steven D'Aprano steve at pearwood.info
Tue Sep 18 08:21:50 CEST 2012


On Mon, Sep 17, 2012 at 09:19:41PM -0700, Scott Yamamoto wrote:
> 2.7.2 on python for ios(platform is darwin)
> problem reoccured

What problem? Your code works for me.

Please describe:

1) what you expect to happen
2) what actually happens
3) if there is a traceback, COPY AND PASTE the ENTIRE traceback, do not 
summarise or abbreviate it.


> Script:
> 
> import random
> username = ""
> def playername():
>   global username
>   Mlist = ["name1","name2","name3"]
>   Flist = ["name4","name5", "name6"]
>   Llist = ["Lname1","Lname2","Lname3"]
>   username = raw_input("input your desired username: ")
>   if username == "":
>     username = random.choice(Mlist) + " " + random.choice(Llist)
> playername()


> Doesnt return the error during run
> Attempting implementation of try results in indentation errors in later lines

That's because your attempt to implement try is broken.

But why are you using a try? If your function has a bug, FIX THE BUG, 
don't just cover it up with a try...except.



-- 
Steven


More information about the Tutor mailing list