马士兵Python学习笔记_P151_150.实操案例三
一、实操案例三
二、代码示例-计算能量的消耗
num = int(input("请输入您当天行走的步数:"))
calorie = num * 28
print(f"今天共消耗卡路里{calorie}(即 {calorie/1000}千卡)")
print("今天共消耗卡路里%s(即 %s千卡)" % (calorie, calorie/1000))
print("今天共消耗卡路里{0}(即 {1}千卡)".format(calorie, calorie/1000))
print("今天共消耗卡路里" + str(calorie) + "(即 " + str(calorie/1000) + "千卡)")
print("今天共消耗卡路里", calorie, "(即", calorie/1000, "千卡)")
运行结果
D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第17章_实操案例\P151_150.实操案例三.py
请输入您当天行走的步数:10000
今天共消耗卡路里280000(即 280.0千卡)
今天共消耗卡路里280000(即 280.0千卡)
今天共消耗卡路里280000(即 280.0千卡)
今天共消耗卡路里280000(即 280.0千卡)
今天共消耗卡路里 280000 (即 280.0 千卡)
Process finished with exit code 0
三、代码示例-预测未来子女的身高
print("-------------------4、预测未来子女的身高---------------------")
father_height = float(input("请输入父亲的身高:"))
mother_height = float(input("请输入母亲的身高:"))
child_height = (father_height + mother_height) * 0.54
print(f"预测子女的身高为:{child_height}cm")
print("预测子女的身高为:%scm" % child_height)
print("预测子女的身高为:{0}cm".format(child_height))
print("预测子女的身高为:" + str(child_height) + "cm")
print("预测子女的身高为:", child_height, "cm")
运行结果
D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第17章_实操案例\P151_150.实操案例三.py
-------------------4、预测未来子女的身高---------------------
请输入父亲的身高:172
请输入母亲的身高:160
预测子女的身高为:179.28cm
预测子女的身高为:179.28cm
预测子女的身高为:179.28cm
预测子女的身高为:179.28cm
预测子女的身高为: 179.28 cm
Process finished with exit code 0
B站视频链接:https://www.bilibili.com/video/BV1wD4y1o7AS?p=151