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 8209273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:40:03+00:00 2026-06-07T09:40:03+00:00

i am new to Python, and i can’t wrap my head around this. I

  • 0

i am new to Python, and i can’t wrap my head around this. I have following function defined:

def FlipCoins(num_flips):
    heads_rounds_won = 0
    for i in range(10000):
        heads = 0
        tails = 0
        for j in range(num_flips):
            dice = random.randint(0,1)
            if dice==1: heads += 1
            else: tails += 1
        if heads > tails: heads_rounds_won += 1
    return heads_rounds_won

Here is what it should do (but apparently doesn’t): flip a coin num_flip times, count heads and tails, and see if there are more heads than tails. If yes, increment head_rounds_won by 1. Repeat 10000 times.

I would assume that head_rounds_won will approximate 5000 (50%). And it does that for odd numbers as input. For example, 3, 5 or 7 will produce about 50%. However, even numbers will produce much lower results, more like 34%. Small numbers especially, with higher even numbers, like for example 800, the difference to 50% is much narrower.

Why is this the case? Shouldn’t any input produce about 50% heads/tails?

  • 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-07T09:40:05+00:00Added an answer on June 7, 2026 at 9:40 am

    You just got a lot of rounds that are tied

    def FlipCoins(num_flips):
        heads_rounds_won = 0
        tails_rounds_won = 0
        tied_rounds = 0
        for i in range(10000):
            heads = 0
            tails = 0
            for j in range(num_flips):
                dice = random.randint(0,1)
                if dice==1: heads += 1
                else: tails += 1
            if heads > tails: heads_rounds_won += 1
            elif heads < tails: tails_rounds_won+= 1
            else: tied_rounds += 1
        return heads_rounds_won, tails_rounds_won, tied_rounds
    

    will return something like

    >>> FlipCoins(2)
    (2506, 2503, 4991)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very new to python and can't understand why this isn't working. I have a
I'm pretty new to Python programming so I have this question: How can I
I am new to python programming..can someone suggest some way to do the following:
I am new to python,can anybody please explain the following syntax, for i in
I'm new with python and regular expressions. I have this regular expressions and i
I'm a bit new to python and can't figure out why this is not
I'm new to Python and can't understand why a thing like this does not
I am really new to python and I can't find any information about this.
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
Brand new to Python (and programming in general), if this is simple and/or answered

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.