Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Python Problem Reply ASAP, python , programming

views
     
TSmohan_rex
post Aug 23 2015, 03:29 PM, updated 9y ago

New Member
*
Newbie
1 posts

Joined: Aug 2015
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
post Aug 23 2015, 10:20 PM

Getting Started
**
Junior Member
69 posts

Joined: Jan 2015
[quote=mohan_rex,Aug 23 2015, 03:29 PM]

which uni u study?

sin2010
post Aug 23 2015, 10:26 PM

Getting Started
**
Junior Member
139 posts

Joined: May 2010
hard to read without indentation
budi_89
post Aug 23 2015, 10:52 PM

New Member
*
Junior Member
31 posts

Joined: Nov 2011


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
post Aug 24 2015, 02:28 AM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
Those "breaks" rclxub.gif
dstl1128
post Aug 24 2015, 09:18 AM

Look at all my stars!!
*******
Senior Member
4,463 posts

Joined: Jan 2003
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


 

Change to:
| Lo-Fi Version
0.0151sec    0.15    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 01:29 AM