TypeError:“str”对象不可调用以在while循环内打印字典

2024-05-23 14:32:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个码字游戏(也称为替换字符)程序的问题,我一直得到错误'str'对象不可调用。这是我的代码(只是while循环中与此字典相关的部分:

used_pairings = {}

while.....:
    used_pairings[guesschar] = guessletter
    print = ("At this point you can decide whether to delete a character-letter pairing.")
    used_pairings_choice = input("Type 1 to delete a pairing or ENTER to carry on: ")
    if used_pairings_choice == "1":
        print ("These are your pairings so far:")
        print (used_pairings)
    else:
        print ("Continuing program.")

这是我得到的错误:

^{pr2}$

我完全不同意这意味着什么,为什么我得到这个错误信息,所以任何帮助将不胜感激。提前谢谢!在


Tags: to对象程序游戏错误delete字符used
2条回答

如果您正在使用python3+print是一个函数。当您执行print = ("At this point you can decide whether to delete a character-letter pairing.")操作时,您正在用一个字符串重写print内建函数。所以只要从那行删除=就可以修复它。在

问题是,print变量声明。在

print = ("At this point you can decide whether to delete a character-letter pairing.")

在这个语句之后,python的函数print更改为str(字符串)中的print变量。在

请更改变量名并尝试代码。在

相关问题 更多 >