-2

因此,如果您查看第 4 行和第 12 行,您会看到,当我注册时,用户输入的所有内容都应该显示在 txt 文件中,但我没有,如果您查看第 38 行,它会给我一个错误,它告诉我我拥有的一切放在括号之间是不识别的。

 from __future__ import with_statement
from asyncore import write

def reg(Ussername, Password, Age, Real_name, Last_name, Email):
   global file
   file = open ("User_details.txt","a")
   file.write("\n"+Ussername+","+Password+","+Age+","+Real_name+","+Last_name+","+Email)
   file.close
def login():
    pass

def Access():
    if option1 == "login":
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")
        login()
    else:
        print ("Enter all the info we will be asking you to register")
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")

def begin():
    global option1 
    print ("Hi my name is Steve would you like to register or login")
    option1 = input ("Login or Register: ")
    if option1 not in ("login", "register"): 
        begin()
begin()
Access()
reg(Ussername, Password, Age, Real_name, Last_name, Email)
4

2 回答 2

0

您需要将所有这些input字符串传递到您的reg函数中。改变这个:

        print ("Enter all the info we will be asking you to register")
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")

对此:

        print("Enter all the info we will be asking you to register")
        reg(
            input("Ussername: "),
            input("Password: "),
            input("Age: "),
            input("Real name: "),
            input("Last name: "),
            input("Email: ")
        )
于 2022-02-11T20:08:03.383 回答
0

他们不被认可,因为他们不存在。

您应该保存用户输入并将其返回。然后,在执行函数时读取它Access(),并将其传递给reg().

from __future__ import with_statement
from asyncore import write

def reg(Ussername, Password, Age, Real_name, Last_name, Email):
   global file
   file = open ("User_details.txt","a")
   file.write("\n"+Ussername+","+Password+","+Age+","+Real_name+","+Last_name+","+Email)
   file.close
def login():
    pass

def Access():
    if option1 == "login":
        input ("Ussername: ")
        input ("Password: ")
        input ("Age: ")
        input ("Real name: ")
        input ("Last name: ")
        input ("Email: ")
        login()
    else:
        print ("Enter all the info we will be asking you to register")
        Ussername = input ("Ussername: ")
        Password = input ("Password: ")
        Age = input ("Age: ")
        Real = input ("Real name: ")
        Last = input ("Last name: ")
        Email = input ("Email: ")

    return Ussername, Password, Age, Real, Last, Email

def begin():
    global option1 
    print ("Hi my name is Steve would you like to register or login")
    option1 = input ("Login or Register: ")
    if option1 not in ("login", "register"): 
        begin()
begin()
Ussername, Password, Age, Real, Last, Email = Access()
reg(Ussername, Password, Age, Real_name, Last_name, Email)

相同的逻辑适用于登录部分。

于 2022-02-11T20:08:48.623 回答