Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 18th, 2012, 01:33 PM
t3hmobster t3hmobster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 t3hmobster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 43 sec
Reputation 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?

Reply With Quote
  #2  
Old November 18th, 2012, 04:25 PM
Purity_Lake Purity_Lake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 33 Purity_Lake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 25 m 17 sec
Reputation Power: 2
Quote:
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How to return to beginning of if statement when input is wrong?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap