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:
if coin == 2:

>Solution :

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)
# Random number between 10 and 30
n2= random.randrange(10, 31) 
# Random number between 20 and 100 divisible by 2
n3= random.randrange(20, 101, 2)

Also you can see here

Leave a Reply