4.17 LAB: Flip a coin Write a program that simulates flipping a coin to make decisions. The input is how many decisions

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

4.17 LAB: Flip a coin Write a program that simulates flipping a coin to make decisions. The input is how many decisions

Post by answerhappygod »

4.17 LAB: Flip a coin
Write a program that simulates flipping a coin to makedecisions. The input is how many decisions are needed, and theoutput is either heads or tails. Assume the input is a valuegreater than 0.
Ex: If the input is:
the output is:
For reproducibility needed for auto-grading, seed the programwith a value of 1. In a real program, you would seed with thecurrent time. In that case, every program's output would bedifferent, which is what is desired but can't be auto-graded.
Note: A common student mistake is to seed before each call torandom.randint(). But seeding should only be done once, at thestart of the program, after which random.randint() can be calledany number of times.
Your program must define and call the heads_or_tails() functionthat randomly picks 0 or 1 and returns "heads" or "tails". Assumethe value 0 represents "heads" and 1 represents "tails".
Code in Java please**
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply