类型错误:“STR”对象不是在输 入线可调用

问题描述 投票:-1回答:1

我是一个Python初学者寻求一些帮助,这一段代码:

elif exit is False and temp is ('1'):
add_more = True
add_1 = 'y'
while add_more is True:
    races.append(input('What is the name of the race: '))
    print('Racelist is now: ' + str(races))
    add_1 (input('Want to add more? yn '))
    if add_1 is ('y'):
        add_more = True
    else:
        addmore = False

当我运行它,我不断收到以下错误:

Traceback (most recent call last):
  File "C:/Users/David/PycharmProjects/Eclipse/Eclipse.py", line 43, in <module>
    add_1 (input('Want to add more? yn '))
TypeError: 'str' object is not callable

当我注释掉受影响的线路环路工程和不停地问:races.append(input('What is the name of the race: '))(变量races是一个列表)。

我已经打破它我的脖子了一夜,谷歌并没有帮助迄今为止。我不明白为什么该行不工作,但其他输入不工作。 。

python
1个回答
0
投票

这似乎有几件事错在你的代码。在您设置addmore = False else语句,我想这是意味着是add_more = False。此外,我认为你要分配用户响应变量add_1。最后,你不应该使用是比较值。而是使用==!=类型比较。你可以尝试以下

add_more = True
add_again = 'y'
while add_more:
    races.append(input('What is the name of the race: '))
    print('Racelist is now: ' + str(races))
    add_again = input('Want to add more? yn ')
    if add_again.lower() != 'y':
        add_more = False
© www.soinside.com 2019 - 2024. All rights reserved.