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