dimanche 3 décembre 2017

Why is this program not running (Python)

I'm trying to write a program in Python that flips a coin and returns the longest series of heads and tails. It asks the user how many times to flip the coin. For some reason my program isn't running and I cant figure out why. I don't know why it isn't asking the user for the "number of flips" and "as a character string" for example.

import random

def flip():
    flipValue = random.randint(1,2)
    if flipValue == 1:
        side = "Heads"
    else:
        side = "Tails"
    return side

def nStreak():
    number = int(input("Number of flips: "))
    chars = int(input("As a character string: "))
    series = 0
    heads = 0
    tails = 0
    longest_h = 0
    longest_t = 0
    while series != number:
        side = flip()
        series += 1
        if side == "Heads":
            heads += 1
            tails = 0
            if heads == chars:
                longest_h += 1
                heads = 0
        if side == "Tails":
            tails += 1
            heads = 0
            if tails == chars:
                longest_t += 1
                tails = 0
    print("Number of heads streaks: ", longest_h)
    print("Number of tails streaks: ", longest_t) 

When I run it I get nothing.




Aucun commentaire:

Enregistrer un commentaire