Tuesday Tip #18: Monty Hall problem 🐐🚘🐐 (Code Challenge #1!)


Hi Reader,

This is a "special edition" of Tuesday Tips! πŸ’Œ

Instead of the usual format, I'm going to pose a coding question and ask YOU to write the solution!

You can send me your solution, and I'll showcase the best solutions in next week's newsletter! πŸ†


πŸ‘‰ Code Challenge #1: Monty Hall problem

There's a classic probability puzzle based on the TV game show "Let's Make a Deal" and named after its host, Monty Hall. Here's the puzzle:

You are a contestant on a game show. In front of you are three closed doors. Behind one of the doors is a car, and behind the other two doors are goats. Your goal is to pick the door with the car.

The host asks you to choose a door. You tell the host your choice. Instead of telling you whether your choice was correct, the host (who knows which door contains the car) opens one of the two doors you didn't choose and reveals a goat.

You now have the opportunity to keep your original choice or switch your choice to the door that is still closed. Which should you choose?

For example, let's pretend that you started by choosing door #1. The host opens door #3 to reveal that it contains a goat. Should you keep your original choice of door #1 or switch your choice to door #2?


Use simulations for problem-solving

One of the "superpowers" of being able to write code is that you can use simulations in order to solve problems like these! In this challenge, I want you to write Python code to simulate this problem.

Specifically, I want you to simulate that you are a contestant on this show 1000 times. Each time, you pick a random door as your first choice, let the host open a door that reveals a goat, and then switch your choice to the door that the host didn't open. With that strategy (known as the "always switch" strategy), how often do you win the car?

Here are a couple of details that I want to be clear about:

  • Before starting each game, the host randomly selects which door contains the car.
  • After you make your initial choice, the host always opens one door that contains a goat, and it will always be a door that you did not initially choose. (If the host has two options for which door to open to reveal a goat, he will randomly select which of those two doors to open.)
  • After the host opens a door that contains a goat, you will always be given the option to switch your choice to the door that is still closed, and you will always accept that option.

If you have questions about any other details, please let me know!


How to submit your solution

The goal of this challenge is to practice writing Python code to solve a problem. In other words, I don't just want to know the "answer" to this puzzle, rather I want to see the code you wrote to solve the problem!

There are two ways you can submit your code to me:

  1. Copy and paste your code into a GitHub Gist and send me the URL. (Read Tuesday Tip #6 for details about Gist.)
  2. Run your code in a Colab notebook and send me the URL. (However, you must click the "Share" button and change the "General access" to "Anyone with the link".)

Please don't copy and paste your code into an email, send me a screenshot of your code, or send me your code as a file attachment. πŸ“Ž

In next week's newsletter, I'll showcase the best solutions! I'm looking for code that is concise, easy-to-read, and represents the data in an elegant way.

If you used an AI tool to help you write the code, please let me know. I'm guessing that the most elegant solutions will come from humans, not AI! πŸ€–


If you enjoyed this week’s newsletter, please forward it to a friend! Takes only a few seconds, and it really helps me out! πŸ™Œ

See you next Tuesday!

- Kevin

P.S. Data structure humor​

Did someone awesome forward you this email? Sign up here to receive data science tips every week!​

Learn Artificial Intelligence from Data School πŸ€–

Join 25,000+ intelligent readers and receive AI tips every Tuesday!

Read more from Learn Artificial Intelligence from Data School πŸ€–

Hi Reader, Until 8 PM ET tonight, you can get the All-Access Pass for $99: Here's everything you need to know: Access all existing courses for one year ($700+ value) Includes new courses launched during your subscription Includes e-book version of Master Machine Learning (coming soon) Additional discounts available Lock in this price forever 30-day refund policy Get the Pass for $99 Questions? Please let me know! - Kevin

Hi Reader, I wanted to share with you three limited-time resources for improving your Python skills... 1️⃣ Algorithm Mastery Bootcamp πŸ₯Ύ Are you looking for an intense, 12-day Python bootcamp? My friend Rodrigo GirΓ£o SerrΓ£o is running a new Algorithm Mastery Bootcamp, and it starts in just 5 days! In the bootcamp, you'll solve 24 real programming challenges and participate in daily live sessions to discuss and compare solutions. It's a great way to strengthen your problem-solving muscles πŸ’ͺ I...

Hi Reader, Last week, I launched the All-Access Pass, which gives you access to ALL of Data School's courses for one year. Through Black Friday, you can buy the pass for $99, after which the price will increase. Here are the included courses: Build an AI chatbot with Python ($9) Create your first AI app in 60 minutes using LangChain & LangGraph! ⚑ Build AI agents with Python ($99) Develop the skills to create AI apps that can think and act independently πŸ€– Conda Essentials for Data Scientists...