【发布时间】:2019-11-18 21:32:44
【问题描述】:
如何创建这个循环,如果欢迎不等于“是”或“否”,它会重复问题(如果他们有帐户),但如果欢迎等于“是”或“否”,他们创建一个帐户(对于“否”)或允许用户登录(对于“是”)?
提前致谢
以下是我使用的代码:
welcome = input("Do you have an account? Please type either 'yes'/'no': ")
if welcome == "no":
while True:
username = input("OK. Let's create an account. Enter a username:")
password = input("Enter a password:")
password1 = input("Confirm password:")
if password == password1:
file = open(username+".txt", "w")
file.write(username+":"+password)
file.close()
welcome = "yes"
break
print("Passwords do NOT match!")
if welcome == "yes":
while True:
login1 = input("OK. Enter your username:")
login2 = input("Enter your password:")
file = open(login1+".txt", "r")
data = file.readline()
file.close()
if data == login1+":"+login2:
print("You have successfully logged in as, " + login1)
print("")
print("Welcome to the Music Quiz!")
break
print("Incorrect username or password.")
【问题讨论】:
标签: python python-3.3