Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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_Syntax Error - Fatal编程技术网

Python编程语言登录错误

Python编程语言登录错误,python,syntax-error,Python,Syntax Error,我是Python的绝对初学者,但我使用过一些visual basic.net。我目前正在使用一对列表作为数据库形式进行登录,但在运行模块时收到一个错误。正如我所说,我是一个绝对的初学者,所以这可能是愚蠢的,但任何帮助解决这个错误将非常感谢,谢谢 以下是*.py文件: username = ["nathan","george"] password = ["password","password"] usrindex = 0 psswrdindex = 0 usrnm = input("user

我是Python的绝对初学者,但我使用过一些visual basic.net。我目前正在使用一对列表作为数据库形式进行登录,但在运行模块时收到一个错误。正如我所说,我是一个绝对的初学者,所以这可能是愚蠢的,但任何帮助解决这个错误将非常感谢,谢谢

以下是*.py文件:

username = ["nathan","george"]
password = ["password","password"]

usrindex = 0
psswrdindex = 0

usrnm = input("username:")
while usrindex < len(usrnm):
    if username[usrindex] == usrnm 
    Then psswrd = input("password:")
        while psswrdindex < len(psswrd):
            if password[psswrdindex] == psswrd
                Then print("Success")
                Else psswrdindex = psswrdindex + 1
    Else usrindex = usrindex + 1
print("Failure")

就像我说的,任何帮助都将不胜感激

结尾需要一个冒号:

if username[usrindex] == usrnm:
当然,这只修复了
语法错误
。您还将得到大量的
namererror
s,因为您的代码不是真正的Python。如果说
Else
Then
没有定义,就会爆炸

Python if语句的组成如下:

if condition:
    ...
elif condition:
    ...
else:
    ...
以下是我认为您实际需要的:


这将详细介绍所有的基础知识。

您在行尾缺少一个冒号:

 if username[usrindex] == usrnm:

if
块的Python语法:

if condition:
    statement
else:
    statement

您必须学习python语法

也许有助于学习

username = ["nathan","george"]
password = ["password","password"]

usrindex = 0
psswrdindex = 0

usrnm = raw_input("username:")
success = False
while usrindex < len(username):
    if username[usrindex] == usrnm:
        psswrd = raw_input("password:")
        while psswrdindex < len(password):
            if password[psswrdindex] == psswrd:
                print("Success")
                success = True
                break
            else:
                psswrdindex = psswrdindex + 1
        break
    else:
        usrindex = usrindex + 1

if not success:
    print("Failure")
username=[“nathan”,“george”]
密码=[“密码”,“密码”]
usrindex=0
psswrdindex=0
usrnm=原始输入(“用户名:”)
成功=错误
而usrindex
我建议阅读基本的python教程。您误解了python语法
username = ["nathan","george"]
password = ["password","password"]

usrindex = 0
psswrdindex = 0

usrnm = raw_input("username:")
success = False
while usrindex < len(username):
    if username[usrindex] == usrnm:
        psswrd = raw_input("password:")
        while psswrdindex < len(password):
            if password[psswrdindex] == psswrd:
                print("Success")
                success = True
                break
            else:
                psswrdindex = psswrdindex + 1
        break
    else:
        usrindex = usrindex + 1

if not success:
    print("Failure")