Theoretically, when randomization is used, the same word may be printed several consecutive times, or it may be printed repeatedly (for example, 3 times out of 5 attempts the same word may be printed). I know, this is correct, this is right and normal.
I would like to set the same value of a variable to be printed again only after four times, therefore on the fifth attempt. I simply want to set some sort of "block" for each value and this block must last for four print attempts.
For example, in my code, I would like in the a_random variable, if Word A2
is printed, then Word A2
will only be able to print again after four subsequent printing attempts, but I want to print only one random word among the four (and not print four words).
For example, if I print Word A2
, the subsequent prints must be 4 random among "Word A1", "Word A3", "Word A4", "Word A5", "Word A6", "Word A7", "Word A8"
, then on the fifth attempt it will be able to print Word A2 again (but not mandatory, because in addition to Word A2 it will be possible to print any word).
Important: I want to print only one word at a time. I don't want to print four words or more words at a time. The output I would like is only one word.
import random
import tkinter as tk
from tkinter import ttkroot = tk.Tk()
root.geometry('300x200')def func():a = "Word A1", "Word A2", "Word A3", "Word A4", "Word A5", "Word A6", "Word A7", "Word A8"print("NEW")a_random = print(random.choice(a))print(" ") return a_randombutton = ttk.Button(root, text='Random', command=func)
button.place(x=10, y=10)root.mainloop()