Get the input from user

Alex Martelli aleaxit at yahoo.com
Mon Apr 3 11:53:06 EDT 2006


<sushant.sirsikar at gmail.com> wrote:

> hi,
>     I am doing example of address book.when user enter stop and presses
> enter my loop should stop.But there is some prob in my loop.It is
> accepting \r after pressing Enter key.How do i check end of input :
>       addressbook={}
> name = raw_input("Enter Name (stop to Finish)")
> 
> name = EnterAddress(addressbook)
> 
> ShowAddress(name, addressbook)
> 
> def ShowAddress(name, addressbook):
>     name = raw_input("Enter Name for Address ")
>     print "Address of %s is %s" %(name,addressbook[name])
> 
> def EnterAddress(addressbook):
>     while name != "stop":
>         entry = raw_input("Enter the address")
>         addressbook[name]=entry
>         name = raw_input("Enter Name (Leave blank to Finish)")
>     return name

Add 'name' to the arguments of EnterAddress, just as you correctly have
it in ShowAddress.


Alex



More information about the Python-list mailing list