gpt4 book ai didi

python - 类型错误: 'str' 对象不可调用

转载 作者:行者123 更新时间:2023-11-28 19:56:19 24 4
gpt4 key购买 nike

我是 Python 的新手,我想知道是否有人可以帮助我编写这段代码:

print("What is your name:")
name = raw_input()
print "hi", name, "How are you:"
Feeling = raw_input()
if Feeling ("good"):
print ("Good")
Else
print ("Thats a shame")

当我运行它时出现错误:

TypeError: 'str' object is not callable

我在网上看过,但找不到任何有用的东西,因为答案太复杂了。

有人可以帮帮我吗

最佳答案

您正在尝试将存储在 Feeling 中的字符串用作函数。

if Feeling ("good"):

Feeling"good" 周围的括号之间只有空格,Python 将其视为函数调用。

您可能想测试它是否等于 "good" 而不是:

if Feeling == "good":
print "Good"

关于python - 类型错误: 'str' 对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com