0
Having issues detecting blank inputs
https://code.sololearn.com/cnsj6atyUb2A/#py How do I prevent a user from entering a blank entry for the requested input? I figured out how to prevent spaces, but a blank input is still accepted if a user just presses enter. I outlined the part of this code that blocks spaces, but it doesn't block the blank entry
4 Respostas
+ 1
When you check a string for True or False, it is True if there's *anything* in it (even a space), and False, if there's nothing in it.
input, if the user just hits enter, gives an empty string.
And you can just test for that.
inp = input()
if not inp:
print('What, no input?')
+ 1
Generally (not on Sololearn) I'd take input in a while loop, then break if all my conditions are met.
while True:
inp = input()
if ...:
break
To check if a str is empty, you can just use 'not inp' - str is False when it is of zero length.
+ 1
Please explain that line.
"not inp" -str is False
Why the negative sign in front of str and how does this accomplish the zero length? Ive tried len to no success and I am confused as to why this would work. Thank you very much 👍 Not trying to be difficult just really dont understand that line
0
Ah. I see what you mean. Thank you kind one! I guess I was making this way more complicated than it had to be haha.
EDIT
I'm going to have to research this a bit I think