import random class GVCoin : def __init__(self, seed): random.seed(seed) self._is_heads = True self.heads = 0 self.flips = 0 def num_flips(self): return self.flips def num_heads(self): return self.heads def num_tails(self): return self.flips - self.heads def flip(self): self.is_heads = random.randint(0, 1) self.flips += 1 if self.is_heads == 1: self.heads += 1 def get_is_heads(self): return self.is_heads def consecutive_heads(gv_coin, goal): # Type your code here if __name__ == "__main__": gv_coin = GVCoin(15) num_heads = 5 num_flips = consecutive_heads(gv_coin, num_heads) print('Total number of flips for 5 consecutive heads:', num_flips)
import random
class GVCoin :
def __init__(self, seed):
random.seed(seed)
self._is_heads = True
self.heads = 0
self.flips = 0
def num_flips(self):
return self.flips
def num_heads(self):
return self.heads
def num_tails(self):
return self.flips - self.heads
def flip(self):
self.is_heads = random.randint(0, 1)
self.flips += 1
if self.is_heads == 1:
self.heads += 1
def get_is_heads(self):
return self.is_heads
def consecutive_heads(gv_coin, goal):
# Type your code here
if __name__ == "__main__":
gv_coin = GVCoin(15)
num_heads = 5
num_flips = consecutive_heads(gv_coin, num_heads)
print('Total number of flips for 5 consecutive heads:', num_flips)
![Given main() and GVCoin class, complete function consecutive_heads() that counts and returns the number of flips taken to achieve a
desired number of consecutive heads without a tails. Function consecutive_heads() 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 pseudo-random number generator with a fixed seed
value. The program uses a seed value of 15 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 pseudo-random numbers.
Ex: If the GVCoin object is created with a seed value of 15 and the desired number of consecutive heads is 5, then the function
consecutive_heads() returns 16 and the program outputs:
Total number of flips for 5 consecutive heads: 16](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1e730ebe-f501-4f88-aec9-bb6e8da611eb%2F8d15b4eb-e6a1-4c3e-b6ee-79974597b2d2%2Fho9d3h_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)