+ 2
Why doesn't this code work?? (SOLVED)
I want to check if the "password" has a number, but the code says it has the number even tho it doesn't https://code.sololearn.com/cDZZ0d5zOaK5/?ref=app
11 Respostas
+ 12
password = "Numb4r"
if "1" in password or "2" in password or "3" in password:
print("Has a number")
else:
print("Doesn't have a number")
Sorry if i am wrong :D
+ 10
This task seems to be good to apply any():
password = "Num4b"
print('number found') if any(i.isdigit() for i in password) else print('no number found')
+ 7
Lothar you can shorten that a bit with a ternary:
print('number found' if any(i.isdigit() for i in password) else 'no number found')
🙂
+ 4
Thanks David, i was not aware of this way using a single print statement with a ternary. Great! 👍
+ 2
Kode Krasher Thanks for showing me this, I watched a few videos about this and will learn it soon.
0
Thanks it works
0
No problem