擅长:python、mysql、java
<p>您的实现有一些错误,举几个例子:</p>
<p>如果试图将函数<code>randm</code>的输出与x进行比较,则需要在函数中包含一个返回值,如下所示:</p>
<pre><code>def randm():
return return_value
</code></pre>
<p>您似乎正在打印所有值,但未将其存储,最后您将只打印最后一个值,您应尝试将其存储在如下列表中:</p>
<pre><code>list_name = [randint(0,100) for x in range(x)]
</code></pre>
<p>这将在列表中生成<code>randint(0,100)</code><code>x</code>次,这将允许您稍后访问所有值。</p>
<p>为了使代码尽可能接近您正在尝试的内容,我将:</p>
<pre><code>import random
def randm(user_numbers):
number = []
for count in range(3):
number.append(random.randint(0, 100))
print(number)
return user_numbers == number
if randm(x):
print('WINNER')
</code></pre>
<hr/>
<p>如果你想用一种非常恶毒的方式来完成这项任务,
你可能想试试这样的方法:</p>
<pre><code>from random import randint
def doLotto(numbers):
# make the lotto number list
lottoNumbers = [randint(0,100) for x in range(len(numbers))]
# check to see if the numbers were equal to the lotto numbers
if numbers == lottoNumbers:
print("You are WinRar!")
else:
print("You Lose!")
</code></pre>
<p>我从您的代码(特别是print()中)假设您正在使用Python3.x+</p>