Letter and number count in raw_input
Question
I am trying to make a password strength tester. The password needs to have at least 4 numbers and 6 letters, so I need to find out how many of each were entered by the user in raw_input
.
Solution
Just iterate over the password:
import string
numbers = 0
letters = 0
for letter in raw_input('Enter a password: '):
if letter in string.ascii_letters:
letters += 1
elif letter in string.digits:
numbers += 1
print numbers, letters
OTHER TIPS
text = "helloworld42"
numbers = sum(c.isdigit() for c in text)
letters = sum(c.isalpha() for c in text)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow