Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6 . Limit flips The function flips uses the module random to flip a coin a certain number of times. It keeps going as long
Limit flips
The function flips uses the module random to flip a coin a certain number of times. It keeps going as long as it sees heads, stopping at the first tails. It then returns the number of heads it saw. Try calling this function in Python:
codio@mikepanther:~workspaceexercise$ python
import funcs
funcs.flips
As you can see, the Terminal hangs and becomes unresponsive. To get control back, you need to press CtrlC In Codio, this can take a long time to respond, and if you hit too many times you can lock up the Terminal. If it takes too long, close the Terminal window and reopen it from the Tools menu.
Obviously this is going to make debugging difficult. So the first thing to do is to limit the loop. You are going to add some code to limit the number of times that the loop will execute. Replace the code
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