Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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 如何检查字符串是否不等于某个值?_Python - Fatal编程技术网

Python 如何检查字符串是否不等于某个值?

Python 如何检查字符串是否不等于某个值?,python,Python,这是我到目前为止问卷的编码。在第6行,如果用户输入的字符集不是1234,我如何使其打印无效 print ("Welcome, Please enter your Canadian Armed Forces Identification Number") answer = raw_input() if answer == ("1234"): print " Please identify yourself " elif answer == "": print " Inv

这是我到目前为止问卷的编码。在第6行,如果用户输入的字符集不是1234,我如何使其打印无效

 print ("Welcome, Please enter your Canadian Armed Forces Identification Number")
 answer = raw_input()
 if answer == ("1234"):
     print " Please identify yourself "
 elif answer == "":
     print " Invalid ID "
     print " 3 More attempts before termination of program "
 name= raw_input()

 if answer == ("Silva"):
     print " Welcome, Silva "

我怎样才能让它重复,直到正确的数字是正确的?如果用户再次输入错误3次,我将如何使程序终止?这是两个不同的问题。我建议你选一本教你所有基本知识的书。好的,非常感谢你
if answer == ("1234"):
    print " Please identify yourself "
else:
    print " Invalid ID "
    print " 3 More attempts before termination of program " name= raw_input()