Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 9 . 9 LAB: Flipping for tails Given main ( ) and GVCoin class, complete function flip _ for _ tails ( ) in

29.9 LAB: Flipping for tails
Given main() and GVCoin class, complete function flip_for_tails() in main.py that counts and returns the number of flips taken to achieve a desired number of tails. Function flip_for_tails() has a GVCoin object and an integer representing the desired number of 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 tails is 100, then the function flip_for_tails() returns 226 and the program outputs:
Total number of flips for 100 tails: 226
import random
class GVCoin:
def __init__(self, seed):
random.seed(seed)
self.is_heads = True
self.heads =0
self.flips =0
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 to_string(self):
str = 'Flips', self.flips,'Heads:',self.heads,'isHeads',self.is_heads
return str
def num_flips(self):
return self.flips
def num_heads(self):
return self.heads
def num_tails(self):
return self.flips - self.heads
def set_to_heads(self, h):
self.is_heads = h
def flip_for_tails(gv_coin, goal):
# Type your code here
if __name__=="__main__":
gv_coin = GVCoin(15)
num_tails =100
total = flip_for_tails(gv_coin, num_tails)
print('Total number of flips for 100 tails:', total);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Will the company help with relocation expenses?

Answered: 1 week ago

Question

In what context did the study and teaching of communication begin?

Answered: 1 week ago