2 ms·
Note the `play` function can be reduced to these 3 lines : chosen = randint(1, 3) winning = randint(1, 3) return (chosen != winning) == switch The
by hk__2 9y ago
Note the `play` function can be reduced to these 3 lines :
chosen = randint(1, 3)
winning = randint(1, 3)
return (chosen != winning) == switch
The only way to win if we don’t switch is to have chosen the winning door (switch==false, chosen==winning); the only way to win if we switch is not to have chosen the winning door (switch==true, chosen!=winning).
- thisacctforreal 9y agoif (chosen == winning && !switch): return true if (chosen != winning && switch): return true return false Is a longer but easier version to read.
- hk__2 9y agoFYI Python uses `and`, not `&&`.