0

I am trying to make a program that will ask the user to input 25 integers.

This is where I'm at now:

while True:
    numbers = list(map(int, input("Enter 25 numbers (seperate it with space): ").split()))
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
A.Brusola
  • 59
  • 5
  • 1
    Welcome to Stack Overflow. Do you know how to check the length of a list? If you check the length of `numbers` afterward, can you use that to solve the problem? What actually is the difficulty? – Karl Knechtel Feb 20 '22 at 16:41
  • Combine Karl Knechtel's comment with [Asking the user for input until they give a valid response](https://stackoverflow.com/q/23294658/354577) – ChrisGPT was on strike Feb 20 '22 at 16:44

1 Answers1

2

This should do the trick. It will prompt you with the question again if you do not enter the right amount of characters. Plus, it does not count spaces as characters.

gettingInput = True

while gettingInput:
    numbers = list(map(int, input("Enter 25 numbers (seperate it with space): ").split()))
    if len(numbers) - numbers.count(" ") > 25:
        gettingInput = True
    else:
        gettingInput = False
# (- numbers.count(" ") will not count spaces as characters.)