Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 9 . 8 LAB: Consecutive heads Given main ( ) and GVCoin class, complete function consecutive _ heads ( ) that counts and returns
LAB: Consecutive heads
Given main and GVCoin class, complete function consecutiveheads that counts and returns the number of flips taken to achieve a desired number of consecutive heads without a tails. Function consecutiveheads has a GVCoin object and an integer representing the desired number of consecutive heads without a tails as parameters.
Note: For testing purposes, a GVCoin object is created in the main function using a pseudorandom number generator with a fixed seed value. The program uses a seed value of during development, but when submitted, a different seed value will be used for each test case. Refer to the textbook section on random numbers to learn more about pseudorandom numbers.
Ex: If the GVCoin object is created with a seed value of and the desired number of consecutive heads is then the function consecutiveheads returns and the program outputs:
Total number of flips for consecutive heads:
import random
class GVCoin :
def initself seed:
random.seedseed
self.isheads True
self.heads
self.flips
def numflipsself:
return self.flips
def numheadsself:
return self.heads
def numtailsself:
return self.flips self.heads
def flipself:
self.isheads random.randint
self.flips
if self.isheads :
self.heads
def getisheadsself:
return self.isheads
def consecutiveheadsgvcoin, goal:
# Type your code here
if namemain:
gvcoin GVCoin
numheads
numflips consecutiveheadsgvcoin, numheads
printTotal number of flips for consecutive heads: numflips
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started