我在編程方面有點菜鳥。我想將我的日常學習主題保存在一個串列中,我的代碼有主題編號限制(范圍(3)),但我不明白如何在沒有數量限制的情況下做到這一點。有什么建議嗎?
topics = []
for todays_topic in range(3):
topics.append(input("inter here>> "))
print(topics)
uj5u.com熱心網友回復:
我不確定你的問題,但我猜你想不斷地將你的 todays_topic 添加到你的串列中,直到你想停止。最好使用 while 回圈而不是 for 回圈。使用while True并不斷添加元素。取一個變數并詢問您是否要輸入更多。如果是,則繼續,如果不是,則中斷回圈。您的代碼:
topics=[]
while True:
todays_topic=input("Enter here>> ")
topics.append(todays_topic)
asc=input("Enter more?? Y/N: ")
if asc=="N"
break
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/323926.html
上一篇:按r中的變數分組后的相交元素
