Calculations and Variables

David Raymond David.Raymond at tomtom.com
Thu Oct 31 15:12:43 EDT 2019


How are you getting any value at all? You are trying to do math on string values just like in your infinite loop question.
This should raise
TypeError: unsupported operand type(s) for /: 'str' and 'str'

Also, tips are usually given as percentages. Here with a tip value of 9 you're saying that the tip is 1/9 th of the bill, which is where the number difference is coming from. If someone entered 50 this is saying the tip is 1/50 th of the bill, etc.


-----Original Message-----
From: Python-list <python-list-bounces+david.raymond=tomtom.com at python.org> On Behalf Of ferzan saglam
Sent: Thursday, October 31, 2019 2:46 PM
To: python-list at python.org
Subject: Calculations and Variables

The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44.


bill = (input("Enter the total cost of the meal: \n"))	 	       	  	  	  	    	   	
tip = (input("Enter how much the tip is: \n"))	 	       	  	  	  	    	   	
split = (input("Enter how many people there are: \n"))	 	       	  	  	  	    	   	
total = bill + (bill / tip)	 	       	  	  	  	    	   	
eachPay = total / split	 	       	  	  	  	    	   	
print("Each person will have to pay %.2f" % eachPay)



I am aiming for the result of 43.6, but somehow get the result of 44.44.
(meal cost: 200) (Tip: 9) (people: 5)

I seem to do the calculation below, but get different results each time.
Total * Percentage Amount / 100
-- 
https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list