循环我想编写一个程序,要求用户的年数,然后将温度每个月多达数年,他们在这样的输入决定:嵌套while和for在Python
Which is the first year?: 2015
Month 1: 25
Month 2: 35
.
.
.
12个月,我已经写了一个可行的代码:
这是多年来外环:
loops = int(input("How many years?: "))
count = 1
while count < loops:
for i in range (0,loops):
input("Which is the " + str(count) + ": year?: ")
count += 1
这是个内部循环:
monthnumber = 1
for i in range(0,12):
input("Month " + str(monthnumber) + ": ")
monthnumber += 1
我的问题是,我在哪里放置内环数月,这样的代码将继续这样的:
Which is the 1 year? (input e.g. 2015)
Month 1: (e.g. 25)
Month 2: (e.g. 35)
..... for all twelve months and then continue like this
Which is the 2 year? (e.g. 2016)
Month 1:
Month 2:
我试图把它在不同的地方,但没有成功。
谢谢,但任务是使用一个while循环与它内部的for循环,嵌套。任何想法如何使用我有的代码,但只放置内循环,以便它是正确的? –
@ J.Se如果你真的需要使用它,那么只需在while循环的第一个循环上添加while循环 – The6thSense
@vigneskalai你能告诉我你的意思吗? –