Write a generator that returns True / False randomly


Topic: Write a generator that returns True / False randomly

Solution

import random
def generate_tf():
    rand = random.random()
    if rand > 0.5:
        yield True
    else:
        yield False



List all Python Programs