Outline ·
[ Standard ] ·
Linear+
Python Problem Reply ASAP, python , programming
TSmohan_rex
|
Aug 23 2015, 03:29 PM, updated 9y ago
|
New Member
|
print ('Please enter Yes or No ') #for i in range (1,4) : while True: try: f = raw_input('Is There Any Disable People : ')
except ValueError: print('Invalid') break
if f == 'Yes' or f =='YES' or f == 'yes' : price5 = price-(price * 0.5) print ('My Dear Customer Kindly Pay This Fare($) For Entrance : '), price5 break
elif f == 'No' or f =='NO' or f == 'no': while True: try: m = raw_input (' Is There Any People With Age More Than 65? : ') except ValueError: print ('Invalid') continue if m == 'Yes' or m == 'YES' or m == 'yes': price5 = price - (price * 0.15) print ('My Dear Customer Kindly Pay The Fare($) For Entrance : '),price5 break else: m == 'No' or m == 'NO' or m == 'no' print ('My Dear Customer Kindly Pay The Fare($) For Entrance : '),price break
#i do this code for my uni assigment if i enter yes in disable = i will gt a price if i enter no it will go below if i dont enter neither yes nor no it will ask again for yes or no i want do the same for below in the age >65 prob is if i enter no or yes it show the price but the loop start again and ask again for disable people and the loop didnt work - if i enter neither yes nor no it doesnt ask and print ans if we entered yes in the disable peopl CAN ANYONE EDIT THIS CODE OR TELL THT ERROR I DID
|
|
|
|
chanmun
|
Aug 23 2015, 10:20 PM
|
Getting Started
|
[quote=mohan_rex,Aug 23 2015, 03:29 PM]
which uni u study?
|
|
|
|
sin2010
|
Aug 23 2015, 10:26 PM
|
Getting Started
|
hard to read without indentation
|
|
|
|
budi_89
|
Aug 23 2015, 10:52 PM
|
New Member
|
This is probably the outcome that you want to achieve. I used the same condition for the inner and outer while loops. CODE price = 50 # an example price print ('Please enter Yes or No ') isValid = False while isValid == False: try: f = raw_input('Is There Any Disable People : ') except ValueError: print('Invalid') continue
if f == 'Yes' or f =='YES' or f == 'yes': price5 = price-(price * 0.5) print ('My Dear Customer Kindly Pay This Fare($) For Entrance : '), price5 isValid = True
elif f == 'No' or f =='NO' or f == 'no': while isValid == False: try: m = raw_input ('Is There Any People With Age More Than 65? : ')
except ValueError: print ('Invalid') continue
if m == 'Yes' or m == 'YES' or m == 'yes': price5 = price - (price * 0.15) print ('My Dear Customer Kindly Pay The Fare($) For Entrance : '), price5 isValid = True
elif m == 'No' or m == 'NO' or m == 'no': price5 = price print ('My Dear Customer Kindly Pay The Fare($) For Entrance : '), price5 isValid = True
|
|
|
|
wKkaY
|
Aug 24 2015, 02:28 AM
|
misutā supākoru
|
Those "breaks"
|
|
|
|
dstl1128
|
Aug 24 2015, 09:18 AM
|
|
You want this? CODE price = 50
MSG_PAY = 'My Dear Customer Kindly Pay This Fare($) For Entrance : ' VALID_ANSWER = ('yes', 'no')
DISCOUNT_INFO = [ ('Is There Any Disable People : ', 0.5), ('Is There Any People With Age More Than 65? : ', 0.15), ]
v = '' while v not in VALID_ANSWER: for x in DISCOUNT_INFO: v = '' while v not in VALID_ANSWER: v = raw_input(x[0]).lower() if v == 'yes': price5 = price * (1 - x[1]) break if v == 'no': price5 = price print MSG_PAY, price5
|
|
|
|