我正在嘗試在我撰寫的終端游戲中從字典中保存一些資料,我在字典中獲得了分數,我想呼叫這些分數以將它們寫在筆記上。我試過了:
with open(path, 'w') as File:
File.write(f"player score is {str(score[\"Player\"])}\n"
f"computer score is {str(score[\"computer\"])}")
但這似乎不起作用。如何在不重寫如何保存分數的情況下解決這個問題?
uj5u.com熱心網友回復:
問題可能只是您在使用 f 字串時需要使用不同的"/ ',否則他們會認為他們已經提前結束了。
with open(path, 'w') as File:
File.write(f"player score is {str(score['Player'])}\n")
File.write(f"computer score is {str(score['computer'])}")
注意:f-string 運算式部分不能包含反斜杠
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/492693.html
上一篇:查找嵌套在字典和串列中的鍵和值
