TypeError:无法将“NoneType”对象隐式转换为 str。这是我尝试使用函数将条目硬编码到字典中时遇到的错误。让用户输入有效,并将其放入字典中,但这不起作用。我已经搜索了诸如此类的其他错误(意思是 TypeError。),但我什么也没找到。有此错误的其他两个(This和this)条目与我无关。
所以。我试图让 AweInspiring 和 BeingAwesome 成为一个打印函数,认为它会正确打印到成就字典中,因为简单地将 AweInspiring 和 BeingAwesome 放在那里会导致它说需要定义它。然后它出现了这个错误。我认为它应该工作,但它没有,我不知道为什么。有谁能够帮我?
achievements = {}
AweInspiring = print()
BeingAwesome = print()
def dovar():
global achievements
print('Type in either \'achievement get\' or \'view achievements.\'')
achieve = input()
if achieve == 'view achievements':
print('Achievements')
for x in achievements.keys():
print('Achievement Name: ' + x + '\tFor: ' + achievements[x])
elif achieve == 'achievement get':
achieveget()
elif achieve == 'achieve':
hardachieve()
def achieveget():
print('Add Achievement')
achievename = input('Name of achievement earned: ')
achievedesc = input('How was the achievement earned: ')
achievements[achievename] = achievedesc
dovarloop()
def hardachieve():
achievename = AweInspiring
achievedesc = BeingAwesome
achievements[achievename] = achievedesc
dovar()
def dovarloop():
dovar()
dovar()