Python question please include all steps and screenshot of code. Also please provide a docstring, and comments throughout the code, and test the given examples below. Thanks.
Implement function heads() that takes no input and simulates a sequence of coin flips.
The simulation should continue as long as 'HEAD' is flipped. When the outcome of a flip
is 'TAIL', the function should return the number of 'HEAD' flips made up to that point.
For example, if the simulation results in outcomes 'HEAD', 'HEAD', 'HEAD', 'TAIL', the
function should return 3. NOTE: Recall that random.choice(['HEAD', 'TAIL']) returns
'HEAD' or 'TAIL' with equal probability.
>>> heads()
0 # TAIL is the outcome of the first coin flip
>>> heads()
2 # The coin flips were HEAD, HEAD, TAIL
>>> heads()
1 # The coin flips were HEAD, TAIL
>>> heads()
5 # The coin flips were HEAD, HEAD, HEAD, HEAD, HEAD, TAIL
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- Write a program named stars.py that has two functions for generating star polygons. One function should be implemented using an iteration (a for loop), and another function should be a recursion. It is optional to fill in your shapes. The functions for generating stars should be named star (size, n, d=2) and star_recursive (size, n, level, d=2), where size is the size of the polygon side (edge), n is the number of sides (or angles), d is a density or winding number that should be set to default value 2, and level is the level of recursion initially equal to n.arrow_forwardYour first task will be to write a simple movement simulator on a snakes and ladders board. For this questionyou can ignore the snakes and ladders and just simply assume you only have to deal with moving. You willneed to simulate rolling the die - this can be done by using the Python random module and the randint method.Your function play_game will take as input the length of the board (an integer), "play" the game by rolling the diemultiple times until the sum of rolls is larger or equal to the length of the board. (note: this is one of the possibleand simplest end rules). The function should return the total number of rolls required to finish the the particulargame that was played. Obviously this number will vary as it depends on the specific random rolls performedduring the movement simulation.arrow_forwardPlease fix of couple things in the code below. A couple of things. The input value is the waist size; the pant size is what the program is going to determine. The name valid_input is too generic. The name of the function should reflect what it does; also, start the name of the function with an action verb. For example, read_waist_size We can simplify the reading with the form : Read waist size WHILE waist size is not in the right range DO Show error message Read waist size again Simpler. By the way, the error message should let the user know how not to make the same mistake again. Something like, “This is not a correct size. Enter a value between 26 and 42.” is more helpful. def valid_input():while True:SizeOfPants = int(input("What pants size you are looking for: "))if 26 <= SizeOfPants <= 42:breakelse:print("This is not a correct size. Try Again!!")return SizeOfPants def return_size(SizeOfPants):if 26 <= SizeOfPants < 28:return "XXS"elif 28 <= SizeOfPants…arrow_forward
- Please do not give solution in image format thanku Write a python program that does the following. Make sure it works and can interface with the user in PyCharm. Write a function word count that will take a sentence (string) and return to you the number of words in the sentence. Show it works by calling it with “Cinderella must get to the ball without her slippers.” (Answer should be 9)arrow_forward***python only *** Write a function that takes two parameters, a and b, both are strings taken from "SCISSORS", "PAPER", or "ROCK, and returns True if a wins over b according to the rules of theScissors-Paper-Rock game; False, otherwise. For example, when a is "SCISSORS" and b is "PAPER", the function should return True.arrow_forwardPython question please include all steps and screenshot of code. Also please provide a docstring, and comments throughout the code, and test the given examples below. Thanks. Develop function fingerprint() that takes text (as a string) as input and creates andreturns the text “fingerprint” obtained as follows: replace each word in the text by itslength (i.e., the number of letters) and concatenate these numbers.>>> fingerprint('This is a secret message')'42167'>>> fingerprint('This message has a different fingerprint')'4731911'>>> fingerprint('Very Short')'45'arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education