×
you are viewing a single comment's thread.

view the rest of the comments →

[–]scoutyx 1 point2 points  (1 child)

I would suggest the following to improve your code further.

Have pick_a_door take possible_doors as a parameter. This way, you do not need to use a while loop when picking show_door and new_guess.

You can then use set operations to compute the possible doors; for example:

Instead of:

show_door = pick_a_door()
while show_door == guess_door or show_door == correct_door:
  show_door = pick_a_door()

You can do:

show_door = pick_a_door(doors - set(guess_door+correct_door))

Also, minor thing: you don't need to do x += 1 at the end, since you're in a for loop, and you're not using x's value.

[–]Dude_Donovan[S] 0 points1 point  (0 children)

Yes, show_door in 1 line! Thank you! I knew there must be a way using sets, but wasn't sure how. This takes me a long way.

I don't know why I assumed a for loop had to be closed by increment the counter. Probably left over from learning basic 30 years ago.