[Python] Rounding to two decimal places and converting percentages in tip calculator

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    These are the parameters of the project:

    • If the bill was $150.00, split between 5 people, with 12% tip.
    • Each person should pay (150.00 / 5) * 1.12 = 33.6
    • Format the result to 2 decimal places = 33.60

    bill = input("What is the total bill?")

    # bill is 150.00

    tip = input("What percentage tip would you like to give? 10, 12, or 15?")

    # tip will be 12%

    max_tip = float(tip) / 100

    # split between 5 people
    people = input("How many people to split the bill?")

    max_split = int(bill) / int(people)
    max_cost = int(max_split) * float(max_tip)

    print(f"Each person should pay:{max_cost}")


    This is my current output:

    What is the total bill?150
    What percentage tip would you like to give? 10, 12, or 15?12
    How many people to split the bill?5
    Each person should pay:3.5999999999999996


    I know from earlier lessons you can round(number, 2) and that should signify to python to round two places past the decimal.

    float(max_tip, 2) was the only place that made sense to me, but then my output was:

    line 77, in <module>
    max_cost = int(max_split) * float(max_tip, 2)
    TypeError: float expected at most 1 argument, got 2

    Process finished with exit code 1


    How can I round up two places past the decimal?

    Also, how do I turn 12% into 1.12?

    Continue reading...

Compartilhe esta Página