In a make task you use the skills you have learned to create a program from scratch. There is no starter code: you begin with an empty editor.
Write a program that works out the tip on a restaurant meal.
print, exactly as written below,
followed by an input() on the next line that collects the answer. A price
can have a decimal point in it, so convert it to a float and store it in
a variable.The tip is 4.7
The total price is 28.2
To take 20% of a number, multiply it by 0.2.
Ask the question with its own print, exactly as written:
What did the meal cost?
The question is part of the checked output, so spelling, capital letters and punctuation count.
Money has 2 decimal places, and the calculation does not respect that on its
own: 20% of 7.25 comes out of Python as 1.4500000000000002. Round both
amounts to 2 decimal places before you output them, with round(tip, 2) and
round(total, 2).
Python outputs a rounded number without any trailing zeros, so do not expect
2 digits after the point every time. A tip of 4 pounds 70 is output as 4.7,
and a tip of exactly 4 pounds is output as 4.0.
Input:
23.50
Output:
What did the meal cost?
The tip is 4.7
The total price is 28.2
Input:
19.99
Output:
What did the meal cost?
The tip is 4.0
The total price is 23.99
(20% of 19.99 is 3.998, which rounds to 4.0)
Input:
12.99
Output:
What did the meal cost?
The tip is 2.6
The total price is 15.59
Make sure that you check for the following things:
float() and not int(), since int() refuses a price with a
decimal point in it.= for assignment.input, and the second closing bracket
that float(input()) needs.print is wrapped in str().