Home > Net >  giving string inputs and store them in a list without number limitation
giving string inputs and store them in a list without number limitation

Time:10-19

im kinda noob in programming. i want to save my daily study topics in a list, my code has topic number limitation(in range(3)) but i don't understand how to do it without number limitation.Any suggestion?

topics = []

for todays_topic in range(3):
    topics.append(input("inter here>> "))
    print(topics)

CodePudding user response:

I'm not sure about your question but I'm guessing that you want to add your todays_topic to your list continuosly until you want to stop. It is better to use while loop instead of for loop. Use while True and keep adding elements. Take a variable and ask whether you want to enter more. If yes then continue, if no, then break the loop. Your code:

topics=[]
while True:
    todays_topic=input("Enter here>> ")
    topics.append(todays_topic)
    asc=input("Enter more?? Y/N: ")
    if asc=="N"
        break
  • Related