Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Coin flip errorless glitch (Python)

Why doesn’t this pick heads? The coin looks fine but isn’t working, maybe the randrange is broken?

import random

coin = 0
coin = random.randrange(1,2)
if coin == 1:
    print("tails")
if coin == 2:
    print("heads")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have to write

coin = random.randrange(1,3)

now coin will be 1 or 2. Let’s see an example where we are generating a random integer number within a given range. This example shows all the different forms of random.randrange() function.

import random
# Random number between 0 and 15
n1 = random.randrange(16)
print(n1)
# Random number between 10 and 30
n2= random.randrange(10, 31) 
print(n2)
# Random number between 20 and 100 divisible by 2
n3= random.randrange(20, 101, 2)
print(n3)

Also you can see here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading