How can I write code so that in a game where a 3 digit number is randomly generated (first 2 digits can be 0) I check if the number contains a 9. However, the number cant be 963 or 369. The number is currently generated in a way where each digit is independently generated. Each digit is a different variable so as to make checking win conditions easier.
My current code is below for reference. I know why it does not work but I don't have a solution.
TABLE = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a=0
b=0
c=0
d=0
e=0
for pp in range (100000):
rand1 = random.randint(0,9)
rand2 = random.randint(0,9)
rand3 = random.randint(0,9)
word1 = TABLE[rand1]
word2 = TABLE[rand2]
word3 = TABLE[rand3]
print(word1, word2, word3)
if (word1 == 9 and word2 != 6 and word3 != 3 and word2 != 9 and word3 != 9) or word2 == 9 and word1 != 9 and word3 != 9 or (word3 == 9 and word1 != 3 and word1 != 7 and word2 != 8 and word2 != 6 and word2 != 9 and word1 != 9):
a +=1
print(a)
Aucun commentaire:
Enregistrer un commentaire