天气计划(我已经开始并遇到错误)

时间:2015-04-26 19:04:18

标签: python

我正在尝试将Python程序编写为以下规范:

  

- 存储一年中的每个月,即所选位置的平均每月温度

     

- 选择月份组合,计算并显示这些月份的总平均温度四舍五入到最接近的整数

这是我写的:

months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

#user input
location = input("Where in Scotland are you? ")

for i in range(12):

        temps  = int(input("Enter the average temperature in celsius for []",months[i])) 

monthsSelected = input("Please select a combination of at least two months: ") 

#output
print("Monthly average temperatures: January: [Jan] February: [Feb] March: [Mar] April: [Apr] May: [May] June: [Jun] July: [Jul] August: [Aug] September: [Sep] October: [Oct] November [Nov] December [Dec]")

print("Average Temp for these months:", sum(temps) / 12)

当我运行该程序时,我遇到了这个:

TypeError: input expected at most 1 arguments, got 2

我不明白这意味着什么。任何人都可以提出修复和/或我可以做出的任何改进吗?

(你可能记得我在一个小时前提交的帖子中基本上要求你为我编写我的程序。我接受了用户的建议并阅读了python列表和数组的一些教程并提供了开始我的节目。)

1 个答案:

答案 0 :(得分:0)

两件事: 1 \ Arrays由 [] 定义,所以

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

2 \格式字符串不正确

temps  = int(input("Enter the average temperature in celsius for [%s]" % months[i]))