python第一次实验

文章介绍了两个Python编程示例:一个是将分钟转换为年份和天数,另一个是计算加热水所需的能量。通过整除和取余操作演示了基础的数值计算在实际问题中的应用。
摘要由CSDN通过智能技术生成

一、实验要求

Demo04

minute = int(input("Enter the number of minutes:"))
year = minute // (60 * 24 * 365)
day = minute % (60 * 24 * 365) // (60 * 24)
print(f"{minute} minutes is approximately {year} years and {day} days")
注释:
minute // (60 * 24 * 365):计算年数 用“//”取整运算
minute % (60 * 24 * 365):计算年数时取余的分钟数   进而计算剩余分钟的天数

结果演示:

Demo05

M = float(input("Enter the amount do water in kilograms:"))
initialTemperature = float(input("Enter the initial temperature:"))
finalTemperature = float(input("Enter the final temperature:"))
Q = M * (finalTemperature - initialTemperature) * 4184
print(f"The energy needed is {Q}")

结果演示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值