# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import random
def simulate_probability(num_trials=1_000_000):
count = 0
# Create a list of 18 students: "Jacob", "Caryn", and 16 others.
names = ['Jacob', 'Caryn'] + [f'Student{i}' for i in range(1, 17)]
print(f"Length of names list: {len(names)}")
for _ in range(num_trials):
# Shuffle the list to get a random ordering.
order = names[:]
random.shuffle(order)
# Check if Jacob is first OR Caryn is last.
if order[0] == 'Jacob' or order[-1] == 'Caryn':
count += 1
return count / num_trials
if __name__ == "__main__":
trials = 1_000_000
probability = simulate_probability(trials)
print(f"Estimated probability after {trials} trials: {probability:.5f}")