TypeError:'str'对象不可调用我做错了什么?

2024-09-29 19:33:55 发布

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

我不确定-我找了一个多小时怎么解决它。我重写了4次代码,但仍然无法工作-在所有,这是一个真正简单的代码,但我不知道失败是如何发生的。你知道吗

代码:

pin = '4372'
konto = '5000'
pin_s = False
kontostand = False

while pin_s == False:
    pin_e = input ("Bitte geben Sie ihren Pin ein: ")
    if pin == pin_e:
        pin_s = True
    else:
        pin_s = False

print ("Ihr Kontostand beträgt: ", konto)

while kontostand == False:
    geld_a = input("Bitte geben sie den Betrag ein den sie abheben möchten: ")
    if geld_a > konto:
        print("Ihr Kontostand reicht nicht aus. Er beträgt: ", konto,"€")
        print("Bitte wählen sie einen anderen Betrag.")
    else:
        kontostand = True

print ("Sie heben ", geld_a ("€ ab"))
print ("Ihr neuer Kontostand beträgt: "), konto - geld_a ("€")

错误发生在第23行 我完全看不出我做错了什么,特别是它真的很简单。我是从c++开始的,但对于我的大学来说,我现在必须从python开始。你知道吗

所以。。。有人能告诉我失败在哪里吗?:(


Tags: 代码gtfalseinputpinprintwhilesie
2条回答

谷歌翻译对上下文有点帮助。我想你想做的是这样的:

print("Sie heben {} (€ ab)".format(geld_a))

或者

print("Sie heben " + str(geld_a) + "(€ ab)")

正如其他人所说,括号()表示方法调用,但字符串不是方法。你知道吗

你的括号用错了。似乎您想将一个字符串附加到另一个字符串以进行打印,但它被解释为一个函数调用。请改用逗号:

print ("Sie heben ", geld_a, "€ ab")

相关问题 更多 >

    热门问题