Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do i code this while following the questions directions

+2 votes
asked Dec 11, 2020 by King Cook (180 points)

Question 1

In this scenario, two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends decide to split the bill evenly between them, after adding 15% tip for the service. Calculate the tip, the total amount to pay, and each friend's share, then output a message saying "Each person needs to pay: " followed by the resulting number.

my attempt

bill = 47.28/2

tip = 0.15 *47.28

total = bill + tip

print("each person needs to pay:" + str(total))

1 Answer

0 votes
answered Dec 11, 2020 by Peter Minarik (86,180 points)

So this is Python, right?

The syntax of the code is fine.

The mathematics is not.

'''The bill comes in the amount of 47.28 dollars.'''
bill = 47.28
'''[...] after adding 15% tip for the service'''
tip = bill * 0.15
total = bill + tip
'''The friends decide to split the bill evenly between them, [...]'''
perPersonFee = total / 2
'''Calculate the tip, the total amount to pay, and each friend's share, then output a message saying "Each person needs to pay: " followed by the resulting number.'''
print("Each person needs to pay: " + str(perPersonFee))

Please, note that the actual amount is mathematically correct, but you cannot pay 0.6 cents (the final result is $27.186). So if one wants to be more practical, then the amount needs to be rounded up to whole cents. I'll leave that to be worked out for you. (Search how to round up in Python.)

Good luck! :)

commented Dec 11, 2020 by King Cook (180 points)
thank you this is my first week coding
commented Dec 11, 2020 by Peter Minarik (86,180 points)
Well, it's pretty good.

Keep it up! You'll go a long way.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...