Not sure how Im supposed to solve this probel Wing 101Python

Not sure how I\'m supposed to solve this probel. Wing 101-Python3

Password validator. Write a program (called q1.py) to check the validity of a password chosen by a user. To be considered valid, a password contains at least 1 letter between [A-Z], contains at least 1 letter between [a-z], contains at least 1 number between [0 - 9], contains at least 1 special character from [$ # @], has a minimum length of 6 characters, and has a maximum length of 12 characters. Your program will consist of two user-defined functions: validate(s) and main(). The validate () function implements the validation procedure described above. The parameter (or input) to the function is a string s. If s fits the above criteria, print valid. Otherwise, print not valid. The main() function drives the program and has been written for you. Your goal is to write the validate() function. Example. The user input (which is handled in the provided main() function) is shown on lines with the > symbol. The code you write for the validate() function will provide the output for the lines that are not prefixed with the > symbol. On line 1, the user wants to know if the string F1# is a valid password (line 1). F1# is not a valid password (line 2). Next, the user wants to know of ABdl234@1 is valid (line 3) and it is a valid password (line 4). The program continues in this manner, where the user enters a password and the output shows whether the password is valid or not (lines 5-16). Once the user is done checking password, quit exits the program (line 17).

Solution

def validate(s):
   s = list(s)
   small = [\'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\', \'h\', \'i\', \'j\', \'k\', \'l\', \'m\', \'n\', \'o\', \'p\', \'q\', \'r\', \'s\', \'t\', \'u\', \'v\', \'w\', \'x\', \'y\', \'z\']
   large = [\'A\', \'B\', \'C\', \'D\', \'E\', \'F\', \'G\', \'H\', \'I\', \'J\', \'K\', \'L\', \'M\', \'N\', \'O\', \'P\', \'Q\', \'R\', \'S\', \'T\', \'U\', \'V\', \'W\', \'X\', \'Y\', \'Z\']
   num = [\'0\', \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\']
   schr = [\'$\',\'@\',\'#\']
   tmp = set(s).intersection(set(small))
   if len(tmp)==0:
       return False
   tmp = set(s).intersection(set(large))
   if len(tmp)==0:
       return False
   tmp = set(s).intersection(set(num))
   if len(tmp)==0:
       return False
   tmp = set(s).intersection(set(schr))
   if len(tmp)==0:
       return False
   if len(s)<6:
       return False
   if len(s)>12:
       return False
   return True
print(validate(\'F1#a2345\'))

Not sure how I\'m supposed to solve this probel. Wing 101-Python3 Password validator. Write a program (called q1.py) to check the validity of a password chosen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site