Get the input from user

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sushant.sirsikar@gmail.com

    #1

    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("Ente r Name (stop to Finish)")

    name = EnterAddress(ad dressbook)

    ShowAddress(nam e, addressbook)

    def ShowAddress(nam e, addressbook):
    name = raw_input("Ente r Name for Address ")
    print "Address of %s is %s" %(name,addressb ook[name])

    def EnterAddress(ad dressbook):
    while name != "stop":
    entry = raw_input("Ente r the address")
    addressbook[name]=entry
    name = raw_input("Ente r Name (Leave blank to Finish)")
    return name

    thanks
    Sushant

  • Alex Martelli

    #2
    Re: Get the input from user

    <sushant.sirsik ar@gmail.com> wrote:
    [color=blue]
    > 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("Ente r Name (stop to Finish)")
    >
    > name = EnterAddress(ad dressbook)
    >
    > ShowAddress(nam e, addressbook)
    >
    > def ShowAddress(nam e, addressbook):
    > name = raw_input("Ente r Name for Address ")
    > print "Address of %s is %s" %(name,addressb ook[name])
    >
    > def EnterAddress(ad dressbook):
    > while name != "stop":
    > entry = raw_input("Ente r the address")
    > addressbook[name]=entry
    > name = raw_input("Ente r Name (Leave blank to Finish)")
    > return name[/color]

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


    Alex

    Comment

    Working...