擅长:python、mysql、java
<p>当你试图写一些东西到一个文件的方式,你做它必须是一个字符串,所以这就是为什么第一个失败。
第二个失败,因为(正如错误所说)您试图从未分组的元素中创建一个字符串。为了实现这一点,元素应该是<strong>one</strong>array/list,这样Python就可以从中生成一个合适的字符串:</p>
<pre><code>x = str(['on round',x,username1 ,'has',player1_score , '\n',username2'has', player2_score]) #See the square brackets
</code></pre>
<p>然而,更为Python式的方法是:</p>
<pre><code>x = "on round %s %s has %d \n %s has %d" % (x, username1, player1_score, username2, player2score)
</code></pre>
<p><em>%s插入字符串,%d插入整数,%f插入浮点。请参阅<a href="https://www.learnpython.org/en/String_Formatting" rel="nofollow noreferrer">Learn Python</a>以获取对此的解释</em></p>