Im trying to see how i can see if a number is in a users input. i tried using .isdigit() but only works if its just a number. im trying to add it to a password checker. i also tried .isalpha() but didn't work. what have i done wrong and what do i need to add or change?
here is what i have
password = input('Please type a password ')
str = password
if str.isdigit() == True:
print('password has a number and letters!')
else:
print('You must include a number!')`
You can use a generator expression and an isdigit() within the any function :
if any(i.isdigit() for i in password) :
#do stuff
The advantage of using any is that it doesn't traverse the whole string and will return a bool value if it finds a digit for the first time!
It is equal to the fallowing function :
def any(iterable):
for element in iterable:
if element:
return True
return False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With