息子の九九のお勉強用
code
from random import shuffle def random_kuku(start, end, amount=1): kuku_list = [] for i in range(start, end + 1): for j in range(2, 10): kuku_list.append(f"{i}*{j}={i*j}") if len(kuku_list) < amount: amount = len(kuku_list) shuffle(kuku_list) return kuku_list[0:amount] print('\n'.join(random_kuku(1, 9, 10)))
結果例
2*4=8 4*5=20 1*9=9 7*3=21 4*6=24 9*8=72 2*5=10 4*8=32 5*9=45 6*8=48