Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:40:44+00:00 2026-06-14T23:40:44+00:00

Trying to do the Birthday Program in python. Being a beginner in Python, I

  • 0

Trying to do the Birthday Program in python. Being a beginner in Python, I am having some trouble.

  1. Function duplicates(l) that takes a list l and returns True if it has a duplicate element, and False if it does not.
  2. Function test(count) generates a list of count random integers between 1 and 365 . Function duplicates(l) will test for duplicates.
  3. Function probability(count, num) runs num tests of count people, and counts the number of tests with duplicates. It returns the fraction of the tests with duplicates – the number of duplicates divided by num.

results should look like:

For 2 people, the probability of 2 birthdays is 0.002.

For 3 people, the probability of 2 birthdays is 0.008. and so on…


Stuck on step 2 & 3:

import random

# not sure what to put for count
count = [random.randint(1, 365)]

def duplicates(l):
    if len(l)!=len(set(l)):
        return True
    else:
        return False

def test(count):
    return [random.randint(1, 365)]

#def probability(count,num):

I believe I did step one correctly, but I’m not sure where to go from here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:40:46+00:00Added an answer on June 14, 2026 at 11:40 pm

    You should create the list like this. test isn’t a very useful name. Consider something like make_birthday_list instead

    def test(count):
        return [random.randint(1, 365) for x in range(count)]
    

    The test in duplicates already evaluates to a bool, so you can just do this. It’s not a good idea to use l as a variable name (looks too much like 1) so I changed it to the_list

    def duplicates(the_list):
        return len(the_list)!=len(set(the_list))
    

    You’ll have to run the test over and over to get the probability

    eg.

    num_samples = 10000
    for count in range(100):
        dup = 0
        for test_number in range(num_samples):
            the_list = make_birthday_list(count)
            if duplicates(the_list):
                dup += 1
        print(count, dup/num_samples)   # / returns a float in Python3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write some code that will function like google calendars quick
I'm trying to pull id, gender, birthday, username, friends list and some other information
I am writing a program in python that will take user birthday input and
I am trying to list the people who have birthday this week with this
I am trying to get friend birthday list. But how to find using my
I am trying to add a birthday validation function in my php script to
I am trying to find all users with AD that have a birthday in
I'm trying to create a simple program that tells you your lucky number according
Recently i was trying to export my friends' birthday's list from facebook, where i
I have a form where i'm trying to validate that a field called birthday

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.