Skip to content
Advertisement

Writing a program meant to take in a password and the program tells the user its length and if it is too large, too small, or if it is strong [closed]

#This program prompts the user to enter a password using the input function
#The program assigns the input to a variable named passWord
# The len function is used to get the length of the data in the passWord variable
#the len function puts this value in the variable passwordLength
#The length of the passwordLength variable is printed.

#This is the start of the program

minLength = 6       #this is the minimum password length
maxLength = 12      #this is the maximum password length
passWord = input("please enter a new password – ")

passwordLength = len(passWord)
if passwordLength minLength: #this is the line with the syntax error
    print("your password is " + str(passwordLength) + " characters long")
    print("your password is too short")
    print("your password must be greater than minLength characters")
if passwordLength maxLength:
    print("your password is " + str(passwordLength) + " characters long")
    print("your password is too long")
    print("your password must be less than maxLength characters")
if (passwordLength  minLength) and (passwordLength  maxLength):
    print("Thank you for creating a strong password!")

this is the error message displaying

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/bin/pythonanywhere_runner.py", line 26, in _pa_run
    code = compile(f.read(), filename.encode("utf8"), "exec")
  File "/home/rocegueda/password.py", line 14
    if passwordLength  minLength:
                       ^
SyntaxError: invalid syntax

How do I fix this syntax error on line 14? Not sure what to do as I am new to this. All help is greatly appreciated.

Advertisement

Answer

You just need to ad the comparison operators as outlined here. For your specific code here are the required operators:

#This program prompts the user to enter a password using the input function
#The program assigns the input to a variable named passWord
# The len function is used to get the length of the data in the passWord variable
#the len function puts this value in the variable passwordLength
#The length of the passwordLength variable is printed.

#This is the start of the program

minLength = 6       #this is the minimum password length
maxLength = 12      #this is the maximum password length
passWord = input("please enter a new password – ")

passwordLength = len(passWord)
if passwordLength < minLength: #this is the line with the syntax error
    print("your password is " + str(passwordLength) + " characters long")
    print("your password is too short")
    print("your password must be greater than minLength characters")
if passwordLength > maxLength:
    print("your password is " + str(passwordLength) + " characters long")
    print("your password is too long")
    print("your password must be less than maxLength characters")
if (passwordLength >= minLength) and (passwordLength <= maxLength):
    print("Thank you for creating a strong password!")

Be mindful of the final case where you need to include the min and max password length as True.

Advertisement