我想要做的是隨機生成兩個等於給定數字的數字。然而,爲了獲得所需的答案,我希望它是隨機的。那就是問題所在。如何創建一個在python中給出答案時關閉的循環?
a=(1,2,3,4,5,6,7,8,9,)
from random import choice
b=choice(a)
c=choice(b)
d= c+b
if d == 10:
#then run the rest of the program with the value's c and b in it
#probably something like sys.exit goes here but I am not sure to end \/
else:
# i have tryied a few things here but I am not sure what will loop it around*
(感謝您的幫助:d)
我已經知道創建了一個名爲「正確」的名單,知道努力值a和b追加到列表但不工作。因爲我知道運行程序'的範圍(100)',所以我得到答案。然而,這些價值並沒有附加到新的清單中。這是問題。然後,我要做的事情是在列表右側讀取值0和1,然後使用它們(對不起,它在學校中做得不是很好) 這是用於不添加給定變量的分數。這是第二點,但是。
import sys
right=(0)
y=x+x
from trail in range(y)
a=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
from random import choice
A=choice(a)
B=choice(a)
d=A/B
if d==1:
right.append(A)
right.append(B)
else:
x.append(1)
for/while + break? –