rendered paste bodyimport math
def calcPrice (zone,x):
if zone == 1:
price = x * 1
elif zone == 2:
price = x * 0.8
elif zone == 3:
price = x * 0.5
else:
print zone,' is not a valid zone. Please try again'
return 0
return price
def insertCoin (price):
coin = float(raw_input('Please insert coin : '))
if coin == 0.10 or coin == 0.20 or coin == 0.50 or coin == 1 or coin == 2 or coin == 5 :
if price > coin:
price = price - coin
print 'You have to insert more coins. New price is : ', price
return insertCoin (price)
elif price < coin:
exchange = coin - price
exchangeInCent = round( exchange * 100 )
euros, cents = divmod(exchangeInCent, 100)
print 'Exchange is ',euros,' and ',cents, 'cents'
printExchange(exchange);
else:
print 'Thank You!!'
return 0
else:
print coin ,'is not accepted'
print 'Accepted coins : 0.10 , 0.20 , 0.50 , 1 , 2 and 5 Euros'
return insertCoin(price)
def printExchange (exchange):
changes = [ 0, 0, 0, 0, 0, 0 ]
euros, cents = divmod(exchange, 100)
while euros != 0:
if euros == 5:
changes [0] += 1
euros = euros - 5
elif euros >= 2:
changes [1] +=1
euros = euros - 2
elif euros >= 1:
changes [2] +=1
euros = euros - 1
while cents != 0:
if cents >= 50:
changes [3] +=1
cents = cents - 50
elif cents >= 20:
changes [4] +=1
cents = cents - 20
elif cents >= 10:
changes [5] +=1
cents = cents - 10
print 'You will have back',
if changes[0]!=0 :
print changes[0],'coins of 5 Euro',
if changes [1]!= 0:
print changes[1],'coints of 2 Euro',
if changes [2] != 0:
print changes [2],'coins of 1 Euro',
if changes [3] != 0 :
print changes [3],'coins of 0.5 Euro',
if changes [4] !=0:
print changes [4],'coins of 0.2 Euro',
if changes [5] !=0:
print changes [5],'coins of 0.1 Euro'
print 'Thank You and have a nice day!'
return 0
print 'Please give ticket type :'
print '1 for 1rst zone'
print '2 for 2nd zone'
print '3 for 3rd zone'
zone = int(raw_input('Your choice : '))
x = int(raw_input('Please give amount of tickets : '))
price = calcPrice (zone,x)
print 'The total cost is : ',price
insertCoin (price)