Junior — Senior
Infinite loop with sum accumulation based on a random number
livecode
Task condition
You need to declare the variable total before entering the loop, then start an infinite loop in which a random integer is generated. If the obtained number is even, add 2 to total; otherwise, add 1.
import random
total = 0
while True:
value = random.randint(0, 100)
if value % 2 == 0:
total += 2
else:
total += 1