Advertisement
ssoni

tip2.py

Oct 27th, 2023
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import sys
  2.  
  3. def main():
  4.     subtotal = float(input('How much was the bill? '))
  5.     service = input('How was the service?  (b)ad/(a)vg/(g)ood: ')
  6.     t = calcTotal(subtotal,service)
  7.     print(f'The bill is ${t:.2f}.  Thank you!')
  8.  
  9. def calcTotal(st, svc):
  10.     if svc == 'b':
  11.         tip = .02
  12.     elif svc == 'a':
  13.         tip = .20
  14.     elif svc == 'g':
  15.         tip = .30
  16.     else:
  17.         print('Invalid option')
  18.         sys.exit(1)
  19.  
  20.     total = st * (1+tip)
  21.     return total
  22.  
  23. main()
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement