我正在尝试使用Python中的pickle,但是一直失败。每当我克服一个错误时,就会得到另一个错误消息。运行代码时,我会收到以下消息。我的'else'使用导致语法错误。为什么会这样?
我是Python的新手,但我想不出我做错了什么?
import pickle
def main():
file_mail = open('email.dat','wb')
save_data(file_mail)
file_mail.close()
def save_data(file):
email = {}
count = 0
while count == 0:
print('Add an email: 1')
print('Modify an email: 2')
print('Delete an email: 3')
print('Display the list: 4\n')
choice = input('Enter a number from the list above:')
if int(choice)== 1:
name = input('Name:')
mail = input('E-mail:')
email[name] = mail
print('Added Successfully')
if int(choice) == 2:
name = input('Name:')
mail = input('E-mail:')
email[name] = mail
print('Modified Successfully')
if int(choice) == 3:
name = input('Name:')
mail = input('E-mail:')
email[name] = mail
print('Deleted Successfully')
if int(choice) == 4:
print(email)
else:
print('Invalid selection')
c = input('Do you want to continue y/n: ')
if c.upper() == 'N':
count = 1
print('Invalid Letter')
file_mail = open('email.dat','wb')
pickle.dump(email,file_mail)
file_mail.close()
main()