From my understanding of for loops, you are defining the variable in the first line of the argument, you then use this definition in the body of the loop where you create an expression which involves the variable. Here the for loop is iterating over a sequence of 1-10 and creating a list of head/tails. Why is x (the variable) not referred to in the body, and how does the code know to iterate over the 1-10 sequence if x is not referred to in the if-else statement. Sorry I'm a beginner, so very basic
import numpy as np
np.random.seed(123)
outcomes = []
for x in range(10) :
coin = np.random.randint(0, 2)
if coin == 0:
outcomes.append("heads")
else :
outcomes.append("tails")
print(outcomes)