Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 9 . 9 LAB: Flipping for tails Given main ( ) and GVCoin class, complete function flip _ for _ tails ( ) in
LAB: Flipping for tails
Given main and GVCoin class, complete function flipfortails in main.py that counts and returns the number of flips taken to achieve a desired number of tails. Function flipfortails 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 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 tails is then the function flipfortails returns and the program outputs:
Total number of flips for tails:
import random
class GVCoin:
def initself seed:
random.seedseed
self.isheads True
self.heads
self.flips
def flipself:
self.isheads random.randint
self.flips
if self.isheads :
self.heads
def getisheadsself:
return self.isheads
def tostringself:
str 'Flips', self.flips,'Heads:self.heads,'isHeads',self.isheads
return str
def numflipsself:
return self.flips
def numheadsself:
return self.heads
def numtailsself:
return self.flips self.heads
def settoheadsself h:
self.isheads h
def flipfortailsgvcoin, goal:
# Type your code here
if namemain:
gvcoin GVCoin
numtails
total flipfortailsgvcoin, numtails
printTotal number of flips for tails: total;
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