Last active
September 9, 2015 23:11
-
-
Save Sanjogsharma/78c10951db0bb473f57a to your computer and use it in GitHub Desktop.
Check if two people share the same birthday (python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| random.seed() | |
| def paradox_tester(num_people): #this fucntion tests if num_people share birthday | |
| same_birthdays = 0 | |
| birthdays = [] | |
| for people in range(num_people): | |
| birthdays.append(random.randint(0, 365)) | |
| birthdays.sort() | |
| seen_birthdays = [] | |
| for bday in birthdays: | |
| if bday in seen_birthdays: | |
| same_birthdays += 1 | |
| seen_birthdays.append(bday) | |
| break | |
| else: | |
| seen_birthdays.append(bday) | |
| return same_birthdays |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment