我正在创建一个系统,它会检查用户是否已经申请了用户名,但是在创建帐户时它会询问他们想要的用户名,然后将其发送回选项屏幕以询问他们是否要登录或创建帐户.
def user_create():
f = open("users.txt", "a")
unique = 0
name = input("Enter a username: ")
with open("users.txt", "r") as file:
file_read = csv.reader(file)
filerow = 1
for row in file_read:
if row[0] == name:
print("This username is already taken, try another one")
file.close()
unique = False
break
else:
unique = True
filerow = filerow + 1
if unique == True:
file.close()
elif unique == False:
signin1()
else:
pass
if name.replace(" ", "").isalpha():
print("Name is valid")
else:
print ("Name is invalid")
user_create()
password = input("Enter a password: ")
f.write(name+","+password+",\n")
f.close()
print("Account created")
signin1()
输出:
Enter a username: testuser
1. Login
2. Create
Which one would you like to do?
接下来应该询问用户密码,但它似乎只跳过了一半的代码。
所有登录代码:
def signin1():
print ("1. Login")
print ("2. Create")
choice = input("Which one would you like to do? ")
if choice == "1":
existence = os.path.exists("users.txt")
if existence == False:
print("There are no authorised accounts yet created")
signin1()
else:
mainsignin()
elif choice == "2":
user_create()
else:
print("Invaild choice")
signin1()
def user_create():
f = open("users.txt", "a")
unique = 0
name = input("Enter a username: ")
with open("users.txt", "r") as file:
file_read = csv.reader(file)
filerow = 1
for row in file_read:
if row[0] == name:
print("This username is already taken, try another one")
file.close()
unique = False
break
else:
unique = True
catspeake
噜噜哒
相关分类