Re: Calculations and Variables
On 01/11/2019 17:07, MRAB wrote: On 2019-11-01 12:36, Rhodri James wrote: On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: 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")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. The OP says it prints 44.44. In Python 2, / does integer division, so it would print 44.00. Well, it's inconsistent one way or the other. We'll have to wait for more information. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 2019-11-01 12:36, Rhodri James wrote: On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: 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")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. The OP says it prints 44.44. In Python 2, / does integer division, so it would print 44.00. -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: 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")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 2019-10-31 18:46, ferzan saglam wrote: 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")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? total = bill + (bill / tip) That adds a 1/9 of the bill. It should add 9% of the bill. 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
Re: Calculations and Variables
On 10/31/19 11:46 AM, ferzan...@gmail.com wrote: 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) Don't you mean 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 -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
RE: Calculations and Variables
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 On Behalf Of ferzan saglam Sent: Thursday, October 31, 2019 2:46 PM To: python-list@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 -- https://mail.python.org/mailman/listinfo/python-list
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