Python程序设计——第二章 核心对象、变量、输入和输出

1.风暴的距离

如果n秒是闪电与雷声之间的间隔时间差,风暴的距离则有n/5英里远。编写一个程序,输入间隔时间差n,输出风暴的距离n/5,结果保留小数点后两位。

seconds=input("Enter number of seconds between lightning and thunder:")
miles=float(seconds)/5
print("Distance from storm:",round(miles,2),'miles')

Enter number of seconds between lightning and thunder:1.25
Distance from storm: 0.25 miles

2.三项全能运动

骑车、跑步、游泳一小时所消耗的卡路里分别为200、475和275。一个人每消耗3500卡路里,就可以减掉一磅的体重。编写一个程序,输入每项运动的小时数,并显示消耗掉的体重磅数。

CycHours=int(input("Enter number of hours cycling:"))
RunHours=int(input("Enter number of hours running:"))
SwimHours=int(input("Enter number of hours swimming:"))
CycCal=200*CycHours
RunCal=475*RunHours
SwimCal=275*SwimHours
WeightLoss=(CycCal+RunCal+SwimCal)/3500
print("Weight loss:",WeightLoss,"pounds")

Enter number of hours cycling:2

Enter number of hours running:3

Enter number of hours swimming:1
Weight loss: 0.6 pounds

3. 棒球

编写一个程序,输入棒球队的名字、赢得比赛的数量、输了比赛的数量,并显示球队名字和相应的胜率。

TeamName=input("Enter name of team:")
GamesWon=int(input("Enter number of games won:"))
GamesLost=int(input("Enter number of games lost:"))
WinRate=round(100*GamesWon/(GamesWon+GamesLost),1)
print(TeamName,'won',WinRate,"% of their games")

Enter name of team:Happy Team

Enter number of games won:56

Enter number of games lost:44
Happy Team won 56.0 % of their games

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值