import math print("Enter a tip:") x =input() print("Tip is: " + str(x)) print("Enter a bill/total: ") y = input() print("Bill is: " + str(y)) #this won't work because I need a precision factor (cents) in my ceil() #so use full ints? print("Tip is: " + str((y * x/100)*100)) #cents print("Tip rounded up is: " + str(math.ceil((y * x/100)*100))) #what do I expect? print("Total is: " + str(y + (y * x/100))) #with 3% and 1.85 should be 1.91 print("Total rounded up is: " + str(y + math.ceil((y * x/100)*100)/100))
Output for a good use case:
Enter a tip: 3 Tip is: 3 Enter a bill/total: 1.85 Bill is: 1.85 Tip is: 5.55 Tip rounded up is: 6.0 Total is: 1.9055 Total rounded up is: 1.91
No comments:
Post a Comment