簡體   English   中英

在 Python 中定義函數的問題

[英]Issue with defining functions in Python

def write(name, finalscore, totalquestions, score, file_Object):
    pickle.dump (str(name) + ' got ' + str(finalscore) + ' percent from ' + str(totalquestions) + ' question(s), this is ' + str(score) + ' out of ' + str(totalquestions) + '.') ,file_Object)
    return 

這個函數有什么問題,最后一個括號出現語法錯誤。

我已經導入了pickle並定義了它是數學測驗的一部分的所有變量,我正在嘗試將結果寫入文本文件。

順便說一句,我正在做 GCSE 計算。

如果沒有字符串連接,函數會提高可讀性,您可以更輕松地找到任何錯誤。 例如:

def write(name, finalscore, totalquestions, score, file_Object):
    pickle.dump ("%s got %s percent from %s questions(s), this is %s out of %s." % (name, finalscore, totalquestions, score, totalquestions), file_Object)
    return 

也許你的函數需要更多的調整......(返回 None?)

暫無
暫無

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

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