循環我想編寫一個程序,要求用戶的年數,然後將溫度每個月多達數年,他們在這樣的輸入決定:嵌套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你能告訴我你的意思嗎? –