Throws conditional coin 100 times. Counts how many times the eagle (front) fell, how much tails (back).
The problem is that with the successful completion of one cycle, the random
variable does not change. What to do?
import random throw = 0 front = 0 back = 0 random = random.randint(1, 2) while throw != 100: if random == 1: front += 1 elif random == 2: back += 1 throw += 1 print(back) print(front) print(throw) input("\n\nНажмите Enter, чтобы выйти")
random
to the variable in which you recorded the valuerandom.randint(1, 2)
. Therefore, even putting the expressionrandom = random.randint(1, 2)
into the body of the loop, you get an error. After all, an object of typeint
(which returnsrandom.randint(1, 2)
) does not have arandint
method. Think of another name for the variable (instead ofrandom
, for example,var
) and enter the expressionvar = random.randint(1, 2)
into the loop body. - mkkik