二手产品经理

二手产品经理

THIS IS RENO

在线学Python100天 - 第2周第三天

因为五一假期的原因,这次的学习耽误了很久,学习使我进步,学习使我快乐。

记录#

  1. 复习上节课内容,带小数点的是 float 型,浮点型。整数是 int,整型。
  2. 在 python 使用数学符号进行计算,+ - * / ** % //,加 减 乘 除 平方 余数 除数。
  3. round 函数:四舍五入函数。
    round(_number_, _ndigits=None_)。返回 _number_ 舍入到小数点后 _ndigits_ 位精度的值。 如果 _ndigits_ 被省略或为 None,则返回最接近输入值的整数。
  4. 小费的计算有点意思,对一个完全没接触过的人来说,这种计算方法很奇怪,怪不得需要用到计算器,哈哈!

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)

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。