Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use python to deal with these codes, please! Modify the program from Task 1b so that it now counts the number of heads and/or tails
Use python to deal with these codes, please!
Modify the program from Task 1b so that it now counts the number of heads and/or tails and saves this value in a variable. Use this variable to print the total number of heads and the total number of tails. Calculate the ratio of heads to total coin flips. Hint: Use a variable initialised to 0 as a counter. Each time you get a heads increase the counter by 1. For example: How many times would you like to flip the coin: 10 The coin came up tails The coin came up tails The coin came up heads The coin came up tails The coin came up tails The coin came up tails The coin came up tails The coin came up heads The coin came up heads The coin came up heads Total number of Heads: 4 Total number of Tails: 6 Task 1d Now modify your code to allow the user to enter the probability of the coin flip coming up heads Then calculate the ratio of Heads to total number of flips For example: How many times would you like to flip the coin: 100 What probability would you like to give to heads : 0.95 There were 93 heads and 7 tails Ratio of heads to total flips is 0.93 Task 1e First create a file and save it as Week2_Taskle. Up to this point you have been using the random.random() function to generate a random number between 0 and 1. Using the documentation from the random library, use random.randrange(a) to extend your program so that it uses 3 sided coins Note: What happens if you call random.randrange()? Discuss this with the person sitting next to you and ask your tutor for help if you get stuck Hint: Use 3 variables as counters to keep track of side1, side2 and side3 For example: How many times would you like to flip the coin? 12 The coin came up side 1 The coin came up side 1 The coin came up side 1 The coin came up side 2 The coin came up side 1 The coin came up side 3 The coin came up side 3 The coin came up side 1 The coin came up side 1 The coin came up side 1 The coin came up side 2 The coin came up side 3 Side 1: 7 Side 2: 2 side3: 3Step 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