Due to 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 lesson, with decimals as float type, integers as int type.
- Calculate using mathematical symbols in Python, + - * / ** % //, addition subtraction multiplication division square remainder quotient.
- 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 integer closest to the input value.
- Calculating tips is quite 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)