Step 6 – doing it 10 times
In step 5 I asked you to run the program 10 times.
THEORY: You know from science that repeating an expriment is a way to make it a fair tes.
The same idea works here. If we only do it once we might get 23 random birthdays which are all the same. It's very unlikely, but possible. Repeating the experiment lets us be more certain of the results.
So, let's make Python do the experiment 10 times.
- Change your program as shown
- IMPORTANT: watch the indentation needed
- First set up a variable called shared to count the number of times we get a shared birthday. This needs to start at zero
- Then add a second for loop to repeat the program 10 times
- Indent everything else – be really careful here
- Add the line to add one to shared if there's a match
- Add the print() to keep things easy to read
- Then add the bottom section to print out how many matches you got
- Run your program to check it works (Run > Run module)
It should create 10 sets of birthdays and tell you at the bottom how many times it has matched
Remember, this is random. You'll most likely get 4, 5 or 6 matches, but you might not.