如图,请问我要怎么添加限定条件才好?
current_users=['John','Denny','Pessica','What','Mebal','Karl']
P_current_users=current_users
P_current_users=['JOHN','DENNY','PESSICA','WHAT','MEBAL','KARL']
new_users=['JOHN','MEBAL','Abi','Otter','Bill','Tony']
for new_user in new_users:
if new_user in current_users:
print("The name had been used.Please Try again.")
else:
print("Passed.")
修改了代码,调整了下:
1.添加了列表 P_current_users,它是 current_users 列表的副本,并将所有用户名转换为小写。这样可以在比较用户名时忽略大小写。
2.修改了 if 条件语句中的比较,将 new_user 和 P_current_users 进行比较,以检查用户名是否已被使用。
3.调整了打印的提示消息,根据需求进行了修改。
current_users = ['John', 'Denny', 'Pessica', 'What', 'Mebal', 'Karl']
P_current_users = [user.lower() for user in current_users]
new_users = ['JOHN', 'MEBAL', 'Abi', 'Otter', 'Bill', 'Tony']
for new_user in new_users:
if new_user.lower() in P_current_users:
print("The name has been used. Please try again with a different username.")
else:
print("Passed.")
不知道你这个问题是否已经解决, 如果还没有解决的话:解密压缩包的思路是什么?
答:通过各种密码去尝试解压文件。
用什么解压文件?
答:zip
使用 zipfile
,rar
使用 rarfile
,已经有 Python 大佬给我们写好啦,只需要调用它们的方法即可。
密码从哪里找?
答:程序自行运算或者找密码本。
思路整理清楚之后,就可以开始了。
在Python中,你可以使用if
和elif
语句来为条件语句添加限定条件。下面是一个示例代码:
if condition1:
# do something if condition1 is True
elif condition2:
# do something if condition1 is False and condition2 is True
else:
# do something if condition1 and condition2 are False
在这个示例代码中,我们使用了三个不同的条件来限定执行不同的操作。如果condition1
为True
,则执行第一个if
代码块中的操作。如果condition1
为False
且condition2
为True
,则执行第二个elif
代码块中的操作。如果condition1
和condition2
都为False
,则执行else
代码块中的操作。
你只需要根据自己的需求,在每个条件下编写相应的代码即可。