【发布时间】:2019-02-02 07:48:24
【问题描述】:
编写一个程序,使用嵌套循环来收集数据并计算几年内的平均降雨量。该程序应首先询问年数。外循环将每年迭代一次。内部循环将迭代十二次,每个月一次。内部循环的每次迭代都会询问用户该月的降雨量。在所有迭代之后,程序应显示月数、总降雨量以及整个期间每月的平均降雨量。
input_years=int(input('Enter number of years:'))
for years in range(input_years+1):
total = 0.0
for month in range(13):
input_month=int(input('Enter the amount of rainfall for that month:'))
total=+input_month
average=total/month
print("This is the number of months:",input_month )
print("This is the total number of rainfall",total,"inches")
print("This is the average rainfall permonth",format(average,".2f"))
【问题讨论】:
-
它没有,不。但是您应该自己尝试并找出问题,然后调试任何问题。如果您发现无法解决的特定问题,请创建minimal reproducible example。
-
有关审查代码的问题应在CodeReview 提出。 StackOverflow 适用于具有特定问题/问题的问题。在姐妹网站上发布问题之前,请仔细阅读他们的帮助,他们也有规则。