Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
def num_checker(password):
num_count = 0
ps = str(password)
if any(i.isdigit() for i in range(0, len(ps) - 1)):
num_count = num_count + 1

if num_count == 0:
print("Please have at least 1 number in your password!")

def main():
password = input("Enter your password:")
num_checker(password)


main()

When I try to run this code I get this error

if any(i.isdigit() for i in range(0, len(password) - 1)):
AttributeError: 'int' object has no attribute 'isdigit'

How can i resolve this?

What I have tried:

How do I fix this error? I have tried converting the types but it doesn't seem to be working.
Posted
Updated 15-Jan-19 1:24am
Comments
jaket-cp 15-Jan-19 7:08am    
done a google search for
python int isdigit
https://stackoverflow.com/questions/33049167/attributeerror-int-object-has-no-attribute-isdigit
From the link
isdigit() works only for strings
Member 14118484 15-Jan-19 7:58am    
Ok got it thanks!

1 solution

Python
def num_checker(password):
  num_count = 0
  ps = str(password)
  if not  any(c.isdigit() for c in password):
    print("Please have at least 1 number in your password!")

def main():
  password = input("Enter your password: ")
  num_checker(password)

main()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900