我试着做一个循环,要求每个月的降雨量,并将月份存储在一个列表中。如何通过从列表中提取每个月来创建一个请求输入每个月降雨量的循环?
例子:

months = ["January", "February", "March"]
rainfall = input("What is the rainfall for ", months[0])

我怎样才能做到每个月一个循环?

最佳答案

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
rainfall = []
for month in months:
    answer = int(input("What was the rainfall in {}?".format(month)))
    rainfall.append(answer)

10-02 20:36