470,833 Members | 1,345 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Get the input from user

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

thanks
Sushant

Apr 3 '06 #1
1 1108
<su**************@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
Apr 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by N?ant Humain | last post: by
2 posts views Thread by danielboendergaard | last post: by
9 posts views Thread by chuck | last post: by
5 posts views Thread by Auddog | last post: by
9 posts views Thread by MadingS | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.