为了好玩,我尝试创建一个非常基本的小操作系统,使用Python。到目前为止,我有:
rUsername = input("Create a new user: ")
rPassword = input("Create a password for the user: ")
tUsername = input("Username: ")
def username():
if tUsername != rUsername:
print("User not found.")
blank = input("")
exit()
username()
def password():
if tPassword != rPassword:
print("Incorrect password.")
blank = input("")
exit()
tPassword = input("Password: ")
password()
def typer():
typerCMD = input("")
print ("Hello, and welcome to your new operating system. Type 'help' to get started.")
shell = input("--")
if shell == ("help"):
print("Use the 'leave' command to shut down the system. Use the 'type' command to start a text editor.")
shell2 = input ("--")
if shell2 == ("leave"):
print("Shutting down...")
exit()
if shell2 == ("type"):
typer()
但我希望程序运行,这样它将保存创建的用户名到一个文件,这样你就不必创建一个新的用户名,每次你运行它。有什么建议吗?(请不要用我的“文本编辑器”来评判我,那只是为了登录的目的。)
以下是创建用户和检查系统中是否存在用户的功能。你知道吗
我们使用
Pickle
库以字典结构存储用户详细信息。你知道吗演示代码:
注意:
链接很少:
你可以这样写一个文件
一个简单的程序,它要求用户输入用户名,并检查用户名是否在文件中,如果不存在,它会将用户名写入文件,从而创建一个新的用户,用这个逻辑你应该在路上
您可以创建用户名和相应密码的字典,然后将其保存到json文件中。你知道吗
假设你的辞典是这样的
保存到文件“用户.json“即写操作
读取操作
相关问题 更多 >
编程相关推荐