Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re, sys
- def getTip():
- while True:
- billamount = raw_input("Please enter bill amount in decimal format --> ")
- try:
- mybill = float(billamount)
- break
- except:
- pass
- e = sys.exc_info()[0]
- print("ERROR: %s" % e )
- print("***Amount entered is not a valid decimal format***")
- while True:
- tippercent = raw_input("Please enter percentage of tip amount in as an integer --> ")
- try:
- mytip = int(tippercent)
- break
- except:
- pass
- e = sys.exc_info()[0]
- print( "Error: %s" % e )
- print("***Tip percentage not entered in valid round number format.***")
- tipdecimal = mytip * 0.01
- tipamount = mybill * tipdecimal
- total = mybill + tipamount
- print("Your " + str(tippercent) + "% tip amount for bill of " + str(mybill) + " is: {0:0.2f}".format(tipamount))
- print("Your total bill is: {0:0.2f}".format(total))
- newtip = 0
- getTip()
- while True:
- newtip = raw_input("Would you like to calculate another tip? Y/N --> ")
- try:
- matchY = re.search(r'(?i)Y', newtip)
- matchN = re.search(r'(?i)N', newtip)
- if matchY:
- getTip()
- if matchN:
- print("Goodbye!")
- sys.exit()
- else:
- pass
- except:
- pass
- sys.exit()
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement