编写一个程序来接收密码,该程序会告诉用户它的长度,以及它是太大、太小还是太强
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
#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!")
这是显示的错误信息
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
如何修复第 14 行的语法错误?不知道该怎么做,因为我是新手。非常感谢所有帮助。
您只需按照概述添加比较运算符 here。对于您的特定代码,这里是必需的运算符:
#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!")
请注意最后一种情况,您需要将最小和最大密码长度包含为 True。
#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!")
这是显示的错误信息
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
如何修复第 14 行的语法错误?不知道该怎么做,因为我是新手。非常感谢所有帮助。
您只需按照概述添加比较运算符 here。对于您的特定代码,这里是必需的运算符:
#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!")
请注意最后一种情况,您需要将最小和最大密码长度包含为 True。