擅长:python、mysql、java
<p>基于<a href="https://stackoverflow.com/questions/56191585/using-a-or-an-correctly-in-a-sentence#comment99008299_56191585">comments</a>中的<a href="https://stackoverflow.com/questions/56191585/using-a-or-an-correctly-in-a-sentence#comment99008242_56191585">discussion</a>,我认为以下内容对您有用:</p>
<pre><code>def getDiceRollString(someint):
a_or_an = "an" if someint in (11, 18) or str(someint)[0] == '8' else "a"
return "You rolled %s %d" % (a_or_an, someint)
</code></pre>
<p>你可以试试:</p>
<pre><code>for i in [1, 5, 8, 11, 15, 18, 28, 81, 88, 800]:
print(getDiceRollString(i))
#You rolled a 1
#You rolled a 5
#You rolled an 8
#You rolled an 11
#You rolled a 15
#You rolled an 18
#You rolled a 28
#You rolled an 81
#You rolled an 88
#You rolled an 800
</code></pre>