From what I understand, you wish implementar
a programme which manages each of the tabuadas
randomly.
To develop this algorithm, you will need to carry out the draw with the method choice
class random
.
Also you have to be careful so that the numbers drawn não se repitam
.
In view of these observations I developed the following algorithm...
# Cabeçalho do programa
print(f'=' * 36)
print(f'\033[34m{f"Gerador de tabuadas aleatórias":^36}\033[m')
print('=' * 36)
# Importações de bibliotecas
from random import choice
# Capturando e tratando o número digitado:
while True:
try:
n = int(input('Gerando tabuada aleatória de: '))
if n <= 0:
print('\033[31mValor INVÁLIDO! Digite apenas inteiros maiores que "0"!\033[m')
else:
break
except:
print('\033[31mValor INVÁLIDO! Digite apenas inteiros maiores que "0"!\033[m')
# Lista de valores a ser sorteados:
valores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Sorteio e exibição dos valores:
print(f'\033[32mTabuada aleatória de {n}')
for c in range(1, 11):
x = choice(valores)
prod = (n * x)
print(f'{n} x {x} = {prod}')
# Exclusão do valor sorteado para não incorrer em sorteios duplicados:
valores.remove(x)
Note the functioning of the algorithm in repl it..
Note that this program has been developed as follows:
The first bloco
Code forms the program header.
The second block of code organizes the libraries used. The next block captures and treats the entered value. The next block stores the list from which to draw the values.
The main block of codes is the last one. It is in this code, where the sorteio
, the produto
of the values and the exibição
of the results. Then occurs the remoção
of the drawn list value valores
, thus avoiding that the amount drawn anteriormente
be drawn again.
From this the program will display the tabuada
of a certain number n
in a non-sequential way and, yes, in a aleatória
.
Doubt is still confused and ambiguous
– Sveen