[Tutor] user input help

Jason Staudenmayer jasons at adventureaquarium.com
Wed Jan 5 20:57:03 CET 2011


Hi all, I'm pretty new to programming in general and figured I'd try out python. 
I'm working on a small program to add users to a sqlite db. The problem I'm 
having it dealing with the user input, I'd like to be able to repeat the 
function to get the input if the user doesn't accept it.

here's the code I have now:

def promptInput():
""" Get employee data from user running this program"""

    lname = raw_input("Please enter employees last name\n")
    fname = raw_input("Please enter employees first name\n")
    email = raw_input("Please enter employee email address (or press enter to \
leave blank)\n")
    result = (lname, fname, email)
    return result

def getEmplyInfo():
    # get the data from input
    result = promptInput()
    # print the data so the user can check and verify spelling
    print "Is the following info correct [y/n]\n%s, %s %s" % (result[1], \
    result[0], result[2])
    check = raw_input()
    #see if the user needs to make corrections to the data he entered
    if check == "y":
        print "this check is done so we can add user"
        print "%s, %s %s" % (result[1], result[0], result[2])
    else:
        check = ""
        promptInput()
        
The if else loop is were I'm loosing it. If I select n it will ask for the input 
again but only once. If on the second time around I enter n to re-do it just exits.



Thanks

Jason
 
 
 
..·><((((º>


More information about the Tutor mailing list