Because of the May Day holiday, this study has been delayed for a long time. Learning makes me progress, learning makes me happy.
Record#
- Review the content of the previous class. Numbers with decimal points are float types. Integers are int types.
- Perform calculations using mathematical symbols in Python: + - * / ** % //. Addition, subtraction, multiplication, division, exponentiation, modulus, floor division.
- round function: rounding function.
round(_number_, _ndigits=None_). Returns the value of _number_ rounded to _ndigits_ decimal places. If _ndigits_ is omitted or None, it returns the nearest integer to the input value.
- Calculating tips is interesting. For someone who has never encountered it before, this calculation method is very strange. No wonder a calculator is needed, haha!
CODE#
print("Tip Calculator")
spend = float(input("How much did you spend? "))
tip = float(input("What percentage do you want to tip? "))
people = int(input("How many people in your group? "))
# owe = round(((spend + tip) / people), 2)
bill_with_tip = tip / 100 * spend + spend
bill_per_person = bill_with_tip / people
owe = round(bill_per_person, 2)
print("You each owe $", owe)