#coding:GBK
import json
def getstoredname():
filename = 'username.json'
try:
with open(filename) as f:
username = json.load(f)
except:
return None
else:
return username
def getnewname():
username = input("What is your name? ")
filename = 'username.json'
with open(filename,'a+') as f:
json.dump(username,f)
return username
def greetuser():
username = getstoredname()
if username:
print("Welcome back, " + username + "!")
else:
username = getnewname()
print ("We'll remember you when you come back, " + username +
"!")
greetuser()
这个问题应该怎么改代码?
Questions I answered: Python-QA
import json
'''
If the username has been stored before, load it and ask if it is the user's username, otherwise,
prompt the user to enter the username and store it.
''
filename = 'username.json'
try:
except FileNotFoundError: