所以,我正在编写一些代码,我希望它执行 if 语句来查看输入,如果它看到某个字符,则会打印一条消息。
password = input("password: ")
if(password == "scan for a certain letter or something"):
print("Please use don't use these smybols: / \ ; : , . > < ? ! @ # $ % ^ & * ( ) [ ] { } | ")
如果结果确实如此,则不必是 if 语句,我只是想知道如何去做。
答案 0 :(得分:2)
您可以将 in
运算符与 any()
函数一起使用:
prohibited = set("/ \ ; : , . > < ? ! @ # $ % ^ & * ( ) [ ] { } | ]".split())
password = input("password: ")
if any(char in prohibited for char in password):
print(f"Please use don't use these smybols: {prohibited}")
答案 1 :(得分:1)
我认为用户获取他使用的无效字符的详尽列表以便他可以更正输入会更方便:
"unique": true,
"background": true
})
答案 2 :(得分:0)
我试图用非常简单的逻辑来实现这段代码。并且它完美地工作。
s="/ ; : , . > < ? ! @ # $ % ^ & * ( ) [ ] { } | \ "
s1=s.split()
s3=input("enter the string: ")
for i in s3:
if(i in s1):
print("please dont use the given symbol:",i)