我讨厌在同一天出现另一个问题,更不用说两个了,但现在我需要一种方法来注册和删除帐户。这是整个脚本:
accounts={'Robrajow':'password', 'Hacker':'hack', 'Noob':'lololol1'}
option1=0
option2=0
loop=1
while loop==1:
print "Welcome to Telemology! You can login, register, delete an account, or exit."
loginchoice = raw_input("What would you like to do? ")
if loginchoice=='login':
choice = raw_input("What is your username? ")
choice2 = raw_input("What is your password? ")
if (choice in accounts):
option1=1
else:
option1=0
if (choice2 == accounts[choice]):
option2=1
else
option2=0
if option1==1 and option2==1:
print "Welcome to Telemology,", choice
else:
print "The username or password you entered is incorrect. Please try again or register."
elif loginchoice=='register':
newuser=raw_input("What is your new username? ")
if (newuser in accounts):
newuser=raw_input("That account name is already taken. Please enter another: ")
newpass=raw_input("What is your new password? ")
print newuser,", welcome to Telemology!"
print newpass, "is your new password!"
print "Write it down and hide it!"
elif loginchoice=='delete':
unsure=raw_input("Do you really want to delete your account? It will never return! ")
if unsure=='yes':
choice = raw_input("What is your username? ")
choice2 = raw_input("What is your password? ")
if choice in accounts:
option1=1
else:
option1=0
if choice2 in password:
option2=1
else:
option2=0
if option1==1 and option2==1:
print "Goodbye forever,", choice
else:
print "The username or password you entered is incorrect."
elif unsure=='no':
print "I hoped so."
else:
print "Invalid input."
elif loginchoice==exit:
print "Goodbye!"
loop=0
else:
print "What? You can only input login, delete, register, or exit."
请忽略可以用一个替换的大量错误和复杂的代码行。我只需要一种方法来注册和删除帐户(也就是字典条目)。
如果你决定为我重写整个脚本,非常感谢。