擅长:python、mysql、java
<p>你很接近了!您不需要在if语句中进行任何int到string的转换。以下方法可以很好地工作:</p>
<pre><code>if how_often == 1:
add_file_1(new_1)
elif how_often == 2:
add_file_2(new_2)
elif how_often == 3:
add_file_3(new_3)
else:
add_file_4(new_4)
</code></pre>
<p>作为<a href="https://stackoverflow.com/questions/51275717/how-to-run-a-function-inside-of-an-if-statement-in-python?answertab=active#comment89529364_51275717">Brad Solomon mentioned</a>,它不能工作的原因是因为<code>how_often</code>是一个int,但是你将它与一个字符串进行比较,它们是不相等的。在</p>
<p>请访问<a href="https://repl.it/repls/ScaredGhostwhiteRegister" rel="nofollow noreferrer">https://repl.it/repls/ScaredGhostwhiteRegister</a>以查看此密码子的操作。虽然函数不会实际加载,但您可以根据您提供的输入查看它试图调用哪个函数。在</p>