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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

23.8 LAB: Consecutive heads (Use Python)

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

LAB
23.8.1: LAB: Consecutive heads
0/10
АCTIVITY
main.py
Load default template.
1 import random
3 class GVCoin :
def _init_(self, seed):
random.seed (seed)
self._is_heads = True
4
5
7
self.heads = e
self.flips = 0
def num_flips (self):
return self.flips
10
11
12
def num_heads (self):
return self.heads
13
14
15
def num_tails (self):
return self.flips
16
17
self.heads
18
def flip(self):
self.is_heads = random.randint (e, 1)
self.flips += 1
if self.is_heads == 1:
self.heads += 1
19
20
21
22
23
24
def get_is_heads (self):
return self.is_heads
25
26
27
28 def consecutive_heads (gv_coin, goal):
# Type your code here
29
зе
31 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)
32
33
34
35
36
Transcribed Image Text:LAB 23.8.1: LAB: Consecutive heads 0/10 АCTIVITY main.py Load default template. 1 import random 3 class GVCoin : def _init_(self, seed): random.seed (seed) self._is_heads = True 4 5 7 self.heads = e self.flips = 0 def num_flips (self): return self.flips 10 11 12 def num_heads (self): return self.heads 13 14 15 def num_tails (self): return self.flips 16 17 self.heads 18 def flip(self): self.is_heads = random.randint (e, 1) self.flips += 1 if self.is_heads == 1: self.heads += 1 19 20 21 22 23 24 def get_is_heads (self): return self.is_heads 25 26 27 28 def consecutive_heads (gv_coin, goal): # Type your code here 29 зе 31 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) 32 33 34 35 36
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education