Search code examples
pythonraw-input

Letter and number count in raw_input


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