153. Python Program to Split a Bill Safely
Mediumtry and except
Overview
One try, two except blocks: a different message for each problem.
Problem Statement
Read the bill total (a number, decimals allowed) and the number of people (a whole number). Print what each person pays, with 2 decimal places, like this for 500 and 4:
Each person pays 125.00
Don't crash on bad input:
- If either value is not a valid number, print
Please type numbers only - If the number of people is 0, print
There must be at least one person
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
One value per line, in this order: the total, then the number of people. Example:
500
4
Output
The output for that example:
Each person pays 125.00
The tests try 5 different inputs.