0

I am wondering about how I can make sure the user enters at least one letter or number as an input. With my code if they enter a blank space it accepts it, but I want to be able to make it so they at least enter one thing.

With this code:

s = input("Please enter a sentence")

print("Your sentence is",s)

It allows this:

Please enter a sentence

Your sentence is

I have entered a blank space and it has allowed it. Any idea on how to make sure they enter at least one letter or number?

Help is much appreciated

I.Hull
  • 11
  • 5

1 Answers1

3

You can add while loop like this:

s = ""

while not s.strip():
    s = input("Please enter a sentence")

print("Your sentence is",s)
Fejs
  • 2,734
  • 3
  • 21
  • 40