Question: Write a function that flips a coin; it returns heads or tails. Use that function to write a GetHeadsInARow functions that accepts the number of

Write a function that flips a coin; it returns heads or tails. Use that function to write a GetHeadsInARow functions that accepts the number of heads to roll in a row before you return with total rolls it took to get that number of heads in a row.

Please Code in Python3

my attempt below will not print out the answer and I do not know why

def HeadTails(): from random import randrange """Will simulate the flip of a coin.""" x = randrange(0,2) if x == 0: return 'tails' else: return 'heads'

def GetHeadsInARow(): user = input("Enter how many times you want heads in a row: ") user_heads = int(user) heads = 0 trys = 0 while heads < user_heads: if HeadTails() == 'heads': heads += 1 trys += 1 else: heads = 0 trys += 1 return heads, trys print("You got %d heads and took %d trys" %(heads, trys))

GetHeadsInARow()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!