Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question in Python: Define a function named coin_flip that returns Heads or Tails according to a random value 1 or 0.

Please answer the following question in Python:

Define a function named coin_flip that returns "Heads" or "Tails" according to a random value 1 or 0. Assume the value 1 represents "Heads" and 0 represents "Tails". Then, write a main program that reads the desired number of coin flips as an input, calls function coin_flip() repeatedly according to the number of coin flips, and outputs the results. Assume the input is a value greater than 0.

Ex: If the random seed value is 5 and the input is:

3 

the output is:

Heads Heads Tails 

Note: For testing purposes, a pseudo-random number generator with a fixed seed value is used in the program. The program uses a seed value of 5 during development, but when submitted, a different seed value may be used for each test case.

The program must define and call the following function: def coin_flip()

There is default code give that is:

import random

# Define your function here

if __name__ == '__main__': random.seed(5) # Unique seed number_of_flips = int(input())

# Type your code here.

Please make sure the function is titled coin_flip otherwise the answer will not work. Do not use the same code as the preexisting questions that have been asked on Chegg as the answers were wrong.

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago