Q:

Python program to design a biased coin flip function

belongs to collection: Python basic programs

0

Here, we are going to build a biasedcoin() function using python. The program is so simple as an introductory program and similar to the function coin() for defining a biased coin flip. The function is going to use an inbuilt library naming random. This random python library helps us to choose a random value of the variable within the range or take some random value from a given set.

    random.choice(['H','T','H'])

The above function will choose a random value with a probability of:

    COIN FLIP =  PROBABILITY OF OCCURRENCE
    -    HEAD = 0.67
    -    TAIL = 0.34

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here is the code

import random

# function to return the randon value 
# on biased biased coin FLIP
def biasedcoin():
    return random.choice(['H','T','H'])

# main code i.e. function calling
print('COIN FLIP : ', biasedcoin())
print('COIN FLIP : ', biasedcoin())
print('COIN FLIP : ', biasedcoin())
print('COIN FLIP : ', biasedcoin())
print('COIN FLIP : ', biasedcoin())

Output

COIN FLIP :  H
COIN FLIP :  T
COIN FLIP :  H
COIN FLIP :  H
COIN FLIP :  H

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to design a biased coin flip functi... >>
<< Python program to design a biased dice throw funct...