Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的elif/if语句不起作用_Python - Fatal编程技术网

Python 我的elif/if语句不起作用

Python 我的elif/if语句不起作用,python,Python,它仍然回答他们的密码是弱的,当它假设说他们的密码是中等的时候 当我添加以下内容时: Enter passwordJnnnnn password accepted password is weak 它仍然不起作用,因为: if user in (choice2) or user in str(choice) or user in (choice1): print("password is weak") elif user in (choice2) and user in str(c

它仍然回答他们的密码是弱的,当它假设说他们的密码是中等的时候

当我添加以下内容时:

Enter passwordJnnnnn
password accepted
password is weak
它仍然不起作用,因为:

if user in (choice2) or user in str(choice) or user in (choice1):
    print("password is weak")
elif user in  (choice2) and user in   str(choice1) or  user in (choice) and  (choice) or user in   (choice1) and  (choice2):
    print("your password is medium")
elif user in (choice2) and user in  str(choice1) and user in   (choice):
    print("your password is strong")

当它被认为是强的时候,它会用弱来回答

您需要将您的条件更改为:

Enter passwordLhgg12
password is weak
在其他条件下也是这样

这是因为python将
str(choice)
计算为True,并且第一个条件总是True


阅读中的详细信息。

在每个和/或之间需要一个布尔表达式

您对while循环的评估很好

if user in (choice2) or user in str(choice) or user in (choice1):
你是这个意思

if user in (choice2) or   str(choice) or  (choice1):

其他ELIF也是如此,我发现您的代码有几个问题:

if user in (choice2) or user in str(choice) or user in  (choice1):
您可能需要的是所有字符的列表,其中不包括
,“
25次,所以

choice=str("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")
然后,
choice2
是一个整数元组。。。我猜你又想要角色了:

choice = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  # no need for str(), it is already a str
在这里,您要求输入密码,忘记密码并将密码长度存储在名为
user
的变量中(顺便说一句,
int(len(X))
与刚才的
len(X)
)相同:


在这里,您检查user是否同时小于6和小于12(当然这是除了其他人所说的比较运算符不是分布式的,
user
是一个
int
,其中
choice
choice1
是字符串。我相信如果您尝试
bool,您会得到一个错误(选择中的用户1)

您可以将输入保存为独立于其长度的变量,还可以创建一个集合进行比较:

set(password) & set(choice1)  # is there any overlap between contents of the two?
然后,您的
选择
类别也需要设置,但您可以编写您的
if/elif

password = raw_input("Input password:\n>>")
pass_length = len(password)
pass_chars = set(password)

…etc

choice=string.ascii_大写;choice2=string.digits
@gingerplus谢谢,我从来不知道这些:)
choice2 ="0123456789"
user=int(len(input("Enter password")))
while user <6 and user <12:
    ...
password = input("Enter password")
while not (6 <= len(password) <= 12):
    ...
if user in (choice2) or   str(choice) or  (choice1):
    print("password is weak")
any(ch in choice1 for ch in password)  # is any character from password in choice1?
set(password) & set(choice1)  # is there any overlap between contents of the two?
password = raw_input("Input password:\n>>")
pass_length = len(password)
pass_chars = set(password)
if pass_chars in choice or pass_chars in choice1: