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

  • Home
  • SEARCH
  • 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 7968775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:07:50+00:00 2026-06-04T07:07:50+00:00

I am new to python and i would like to know how to make

  • 0

I am new to python and i would like to know how to make the code to repeat the random.randint part 100 times.

#head's or tail's

print("you filp a coin it lands on...")

import random

heads = 0
tails = 0


head_tail =random.randint(1, 2,)

if head_tail == 1:
    print("\nThe coin landed on heads")
else:
    print("\nThe coin landed on tails")

if head_tail == 1:
    heads += 1
else:
   tails += 1

flip = 0
while True :
    flip +=1
    if flip > 100:
        break



print("""\nThe coin has been fliped 100 times
it landed on heads""", heads, """times and tails""", tails,
"""times""")

input("Press the enter key to exit")
  • 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-04T07:07:52+00:00Added an answer on June 4, 2026 at 7:07 am

    You could do it all in one line with a list comprehension:

    flips = [random.randint(1, 2) for i in range(100)]
    

    And count the number of heads/tails like this:

    heads = flips.count(1)
    tails = flips.count(2)
    

    Or better yet:

    num_flips = 100
    flips = [random.randint(0, 1) for _ in xrange(num_flips)]
    heads = sum(flips)
    tails = num_flips - heads
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Relatively new to Python.. I would like to know how to check if a
I'm new to Python and would like to know of some good framework /
I'm new to OpenCV and would like to use its Python binding. When trying
I use Kodingen.com to test python scripts. I would like to install new python
I'm pretty new to Python programming and would appreciate some help to a problem
I would need some help in python. I'm new in python. I used to
I want to create a MSWindows Python program that would launch a new Firefox
I have been trying to make a cash register like code, where the user
I would like to know how practical it would be to create a program
I'm trying to make a blog/news site and would like to have articles have

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.