Page 1 of 1

Can I have a line by line explanation of how this python program works? Like how each line is implemented from random i

Posted: Sat May 14, 2022 8:35 pm
by answerhappygod
Can I have a line by line explanation of how this python program works? Like how each line is implemented

from random import randint,choice

def choose_door(doors):
return choice(doors)

def money():
doors = [False for _ in range(3)]
chosen_door = randint(0,2)
doors[chosen_door] = True
return doors

def trial():
doors = money()
player_choice = choose_door(doors)
if player_choice:
return 0
else:
return 1

def prize():
TRIALS = 1000
r_switch = 0
for _ in range(TRIALS):
r_switch += trial()
wrong_switch = TRIALS - r_switch
print("Winning money from changing door:",r_switch)
print("Losing money from changing door:",wrong_switch)
print(f"Probability of winning after change: {r_switch*100/TRIALS:.2f}%")
prize()