Home > other >  Ask a user for 10 integers one at a time and store in list- python
Ask a user for 10 integers one at a time and store in list- python

Time:12-06

score = int(input("Please enter a bowling score between 0 and 300: "))

while score >= 1 and score <= 300:
    scores.append(score)

    score = int(input("Please enter a bowling score between 0 and 300: "))

print(scores)

I want the user to enter 10 integers one at a time in a loop and store all ten in a list called scores.

CodePudding user response:

You could do something like this:

ints=[]
for i in range(10):
   ints.append(int(input())

This will repeatedly wait for a user input, and store each value in the ints list. If you want the number to be between 1 and 300, simply place the code you already have in a for loop, or create a counter.

CodePudding user response:

you can do something like this

user_input = []
count = 0
while True:
      if count==10:
           break
      val = int(input("Please enter a bowling score between 0 and 300: "))
      if val>=0 and val<=300:
            user_input.append(val)
            count =1
      else:
          print("value is not between 0 and 300", enter value again")
  • Related