马士兵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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值