Write a python program to figure out how to split a restaurant bill. Your program should prompt the user for the following information: The total amount of the bill, a float. The percentage everyone is willing to tip, a float between 0 and 1. So 0.2 would be entered for a 20% tip. The number of ways to split the bill (i.e. the number of people in the group), an integer. The program should use the information supplied by the user to calculate how much each person should contribute. For example, if the total bill was $60.00, everyone is willing to tip 20% (0.2), and there are 3 people willing to split the bill, then each person should contribute $24. The program should then print that amount for the user. Avoid prompting the user for input or printing to console from inside of any function other tha
Write a python program to figure out how to split a restaurant bill.
Your program should prompt the user for the following information:
-
The total amount of the bill, a float.
-
The percentage everyone is willing to tip, a float between 0 and 1. So 0.2 would be entered for a 20% tip.
-
The number of ways to split the bill (i.e. the number of people in the group), an integer.
The program should use the information supplied by the user to calculate how much each person should contribute. For example, if the total bill was $60.00, everyone is willing to tip 20% (0.2), and there are 3 people willing to split the bill, then each person should contribute $24. The program should then print that amount for the user.
Avoid prompting the user for input or printing to console from inside of any function other than main(). Using the following tips:
-
Instead of prompting for input inside a function, prompt for input inside main(), assign the user’s input to a variable, then pass that variable to your function as a parameter.
-
Instead of printing to the console inside a function, return the data to be printed, call your function from main(), assign the output to a variable, then print the variable.
-
Are you printing to the console multiple times in a function? Split that function into multiple smaller functions – at least one for each print().
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images