[Tutor] user input help

Alan Gauld alan.gauld at btinternet.com
Thu Jan 6 01:52:15 CET 2011


"Jason Staudenmayer" <jasons at adventureaquarium.com> wrote

> I'm working on a small program to add users to a sqlite db.

Try the database topic in my tutorial where I do a very similar 
thing...

> code follows -------------
def promptInput():
    ...
    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 else is not a loop it is a branch.
See the What is Profgramming topic in my tutorial for a description
of the different structures. Then see the loops and branching topics
for loop and branch structures. You need a loop. The topics give 
examples.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list