输入循环列表

时间:2016-02-10 01:49:12

标签: python

这是我到目前为止所做的,有适当的缩进,但我无法在这里知道如何做到这一点。此外,代码显然是不完整的,我只是停留在第一部分。

def main():  
    rains = []  
    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']  
    month = 0  
    rain = int(input('Enter the amount of rain for ', months(month)))
    month += 1  
    print(rain)  

main()

我正在努力寻找降雨量的月份。 所以第一个是&1;输入1月:',然后它附加输入,然后输入2月的输入:',直到输入所有月份。感谢。

1 个答案:

答案 0 :(得分:3)

你做得很好,除了循环和一点点语法糖:

Enter the amount of rain for January: 5
5
Enter the amount of rain for February: 5
5
Enter the amount of rain for March: 5
5
Enter the amount of rain for April: 5
5
Enter the amount of rain for May: 6
6
Enter the amount of rain for June: 8
8
Enter the amount of rain for July: 9
9
Enter the amount of rain for August: 10
10
Enter the amount of rain for September: 16
16
Enter the amount of rain for October: 13
13
Enter the amount of rain for November: 12
12
Enter the amount of rain for December: 10
10
[5, 5, 5, 5, 6, 8, 9, 10, 16, 13, 12, 10]

输出:

$(form).data( 'setting' , data.settingId );