我是一个正在做我的 Pytn 作业的学生。问题是,我们的讲师对我们不使用 pytn 内置的非常严格,并且在提交之前拒绝检查我们的代码,并且我在注册过程中最难让我的代码正常工作。
我目前的问题是,当用户尝试使用已获取的用户名进行注册时,我希望代码提示程序本身出现错误。但是,无论我如何尝试修复它,它都会不断运行不同的错误。任何人都可以请指出我正确的方向或告诉我我的代码有什么问题吗?
def grant():
print("Helllooooo")
def begin():
while True:
print("Welcome to the Freshco Groceries App!")
option = input("Are you a new or returning user?\n"
"Enter 1 if you would like to LOGIN\n"
"Enter 2 if you would like to register\n"
"Enter 3 if you would like to exit the program\n")
if option=="1":
access(option)
break
elif option=="2":
access(option)
break
elif option=="3":
print("Thank you! Have a good day.")
exit()
else:
continue
def access(option):
if(option=="1"):
name = input("Please enter your username:\n")
pword = input("Please enter your pword:\n")
login(name,pword)
else:
print("First step: Please cose a username and a unique pword.")
name = input("Please enter your username:\n")
pword = input("Please enter your pword:\n")
register(name,pword)
newuser()
def login(name,pword):
success=False
file = open("user_details.txt","r")
for line in file:
a,b = line.split(",")
if (name in a) and (pword in b):
success=True
break
file.close()
if(success):
print("You have successfully logged in! Happy spping!")
grant()
else:
print("Wrong username or pword entered.")
def register(name,pword):
exist = False
while True:
file = open("user_details.txt", "r")
for line in file:
line = line.rstrip()
if (name == line):
exist = True
break
else:
p
file.close()
if (exist):
print("Username has been taken. Please try again with a new one.")
break
else:
file = open("user_details.txt","a")
file.write("\n" + name + "," + pword)
print("You have successfully registered! Welcome to the Freshco Family!")
grant()
break
def newuser():
print("Before you start using the app, please fill in the details below.")
alldata = []
while True:
newdata = []
nname = input("Please enter your full name:\n")
newdata.append(nname)
while True:
ngender = input("Are you female or male?\n"
"1: female\n"
"2: male\n")
if ngender=="1":
fingender="female"
newdata.append(fingender)
break
elif ngender=="2":
fingender="male"
newdata.append(fingender)
break
else:
print("INVALID INPUT")
continue
naddress = input("Please enter your address:\n")
newdata.append(naddress)
nemail = input("Please enter your email address:\n")
newdata.append(nemail)
ncontact = input("Please enter your contact number:\n")
newdata.append(ncontact)
ndob = input("Please enter your dob in this format: <DD.MM.YY>\n")
newdata.append(ndob)
alldata.append(newdata)
print(newdata)
break
print("Thank you for entering your information, you will be redirected now!")
grant()
begin()
太感谢你了!T-T
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(82条)