簡體   English   中英

Python 3 打印()函數 - “非類型對象不可調用”

[英]Python 3 print() function - "Non-Type object is not callable"

在空閑(Python 3.4.3)中,我試圖讓它打印出總數(確實如此),但它不會用“......你需要多少糖果”這樣的語句來完成。 它只是出現了這條消息:

非類型對象不可調用

這是我正在輸入的...

children = input ("How many children are there? ")
sweets = input ("How many sweets are there? ")
total = int(children)*int(sweets)
print (total) "is how many sweets you'll need"

我如何讓它在總數之后顯示這個語句?!

非常感謝任何幫助!

這里的問題是,在 python 3 中,print 是一個函數,而不是關鍵字,因此您在打印調用時創建了語法錯誤。 盡管老實說,您編寫的內容也會在 python 2 中出現語法錯誤(但出於不同的原因)。

您可以修改打印調用來工作:

print(total, "is how many sweets you'll need")

或者您可以在打印之前格式化字符串:

print("{0} is how many sweets you'll need".format(total))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM