#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    How to return to beginning of if statement when input is wrong?


    Hi there i'm pretty new to python and programming in general. I've been trying to teach myself while building this "budget planner program". I'd really appreciate some help figuring this out or maybe just lead me in the right direction to where I can figure it myself with some helpful hints

    PHP Code:
    conf1 str(raw_input('Y/N: '))
    if 
    conf1 == 'y' or conf1 == 'Y':
            print 
    'Confirmed'
    elif conf1 == 'n' or conf1 == 'N':
            print 
    'Not Confirmed'
    else:
        print 
    'Please confirm using Y/N please.'
            
    wage_1 float(raw_input('\nHourly Wage: '))
    print 
    'your hourly wage is'wage_1,'correct?'

    conf2 str(raw_input('Y/N: '))
    if 
    conf2 == 'y' or conf2 == 'Y':
        print 
    'Confirmed'
    elif conf2 == 'n' or conf2 == 'N':
        print 
    'Not Confirmed'
    else: 
        print 
    'Please confirm using Y/N please.' 
    So how can I make this to were if the user enters 'N' or nothing at all it will return to the beginning of the if statements?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    33
    Rep Power
    3
    Originally Posted by t3hmobster
    Hi there i'm pretty new to python and programming in general. I've been trying to teach myself while building this "budget planner program". I'd really appreciate some help figuring this out or maybe just lead me in the right direction to where I can figure it myself with some helpful hints

    PHP Code:
    conf1 str(raw_input('Y/N: '))
    if 
    conf1 == 'y' or conf1 == 'Y':
            print 
    'Confirmed'
    elif conf1 == 'n' or conf1 == 'N':
            print 
    'Not Confirmed'
    else:
        print 
    'Please confirm using Y/N please.'
            
    wage_1 float(raw_input('\nHourly Wage: '))
    print 
    'your hourly wage is'wage_1,'correct?'

    conf2 str(raw_input('Y/N: '))
    if 
    conf2 == 'y' or conf2 == 'Y':
        print 
    'Confirmed'
    elif conf2 == 'n' or conf2 == 'N':
        print 
    'Not Confirmed'
    else: 
        print 
    'Please confirm using Y/N please.' 
    So how can I make this to were if the user enters 'N' or nothing at all it will return to the beginning of the if statements?
    Something like this:

    Code:
    def a_Function():
        # code for if statements
        if a == 'y':
            print "yes"
        elif a == 'n':
            a_Function()
    this is called Recursion, where a functions calls itself. This is how you would repeat the if statements but its not a good idea to do it in this senario because if a user says no they mean NO

IMN logo majestic logo threadwatch logo seochat tools logo