为什么我的打印声明不起作用?

2024-03-29 08:28:08 发布

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

我只是一个初学者,所以请容忍我,我有麻烦我的如果和打印声明。有3种选择,A、B或C,这是A:

g = 0

ge = ("Gold =")

gh = ("The amount of gold you have is:")

choice3 = input()

if choice3 == "A":
      print("You slide him the coins through the bars.")(g = g - 5)(gh,g)("'Thanks!' He says. You manage to break out with him and escape to New Mexico, Well done, you win!")

这是我收到的错误消息:

^{pr2}$

Tags: ofthetoyou声明ghamount初学者
2条回答

这是因为print总是在调用后返回None。见下文:

>>> print(print('Hi'))
Hi
None
>>>

通常,Python会忽略这个None。但是,它是存在的,因为Python中的所有函数都必须返回某些。在

此外,在这一部分:

^{pr2}$

{{{{like^{cd6}调用函数返回。在

请记住,Python中的函数是通过在函数后面加上(...)来调用的。在

Here是关于print的参考资料,我想对你有帮助。在

您不应该像那样使用print,而是使用format例如,shown here

text_is = 'amazing'
print('Your text is {}'.format(text_is))

在您的情况下,可能是:

^{pr2}$

相关问题 更多 >