Guided Project: Visualizing Earnings Based On College Majors(2/6)

Screen Link:

My Code:

INITIAL CODE

from numpy.random import seed, randint

seed(1)

def coin_toss():
if randint(0,2) == 1:
return ‘HEAD’
else:
return ‘TAIL’

probabilities =
heads = 0

for n in range(1, 10001):
outcome = coin_toss()
if outcome == ‘HEAD’:
heads += 1
current_probability = heads / n
probabilities.append(current_probability)

print(probabilities[:10])
print(probabilities[-10:])
# Uncomment above and complete code from here

Replace this line with your code

What I expected to happen:

What actually happened:
probabilitieslist (<class ‘list’>)

  • actual + expected
Replace this line with the output/error
1 Like

hello @nextlevellearning123, the way you’ve written your code we can’t know where the problem is.
Follow the following guidelines:

from numpy.random import seed, randint

seed(1)

def coin_toss():
    if randint(0,2) == 1:
        return 'HEAD'
    else:
        return 'TAIL'
    
probabilities = []
heads = 0

for n in range(1, 10001):
    outcome = coin_toss()
    if outcome == 'HEAD':
        heads += 1
    current_probability = heads / n
    probabilities.append(current_probability)

print(probabilities[:10])
print(probabilities[-10:])