Get the input from user

  • Thread starter sushant.sirsikar
  • Start date
S

sushant.sirsikar

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
 
A

Alex Martelli

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,160
Latest member
KieranKisc

Latest Threads

Top