mercredi 12 octobre 2022

Python: random numbers list and index

I want to create a sudoku game.

My idea is to generate 9 random lists and that the for loop goes through each individual line and after reading each index, it is compared with the previous line with the same index.

How to use index a[n] == b[n] when I have n lines? a, b, c and etc.

For now, that's all I have below:

Random number generator

import random

row = range(1, 10)
print(random.sample(row, k=9))

Number compatibility

a = [1, 2, 4, 5]
b = [1, 2, 4, 5]


counter = 0
for i in a:
    if i == b[counter]:
        print("the numbers match" + str(i) + str(counter))
    else:
        print("the numbers do not match" + str(i) + str(counter))
    counter += 1

Thank you




Aucun commentaire:

Enregistrer un commentaire