Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use python for this programming task, thank you Task 5. Flipping s The goal of this task will be to simulate random coin tosses for
Use python for this programming task, thank you
Task 5. Flipping s The goal of this task will be to simulate random coin tosses for both a biased and unbiased coin. To complete this task we will need to look at importing a second library, just like we did the math library. The lbrary we will be importing is the random library allowing the programmer to access tools to generate pseudo-random number and perform operations that use these tools. See Task 5a Write a program that generates and prints some random numbers using the 'random.randam)' command. What values are generated by this command? Note: What happens when you type 'random.randomin ldle. Discuss with your programming partner what this informatian means. Ask you practical tutor if you are not sure. Task 5b Write a program that simulates an unbiased coin fip. Your program should print true if the coin flip results in a head and false if the coin fip results in a tail. Hint 1: First generate a random number and save it in a variable Hint 2: What happens when you type 4 5or5 4 in the interactive shell. The random number generated is: 0.581785013980369 Output (Heads is True, Tails is False): True Task 5c Naw consider a biased coin. Write a program that takes a value p, with range between 0 and 1, as input from the user and tests a coin fip where p is the probability of the flip resulting in heads. Hint 1: As an example if the probability is 0.8, this means that if the randam number generated is 0.2 it is a heads, if it is O.95 it is tails, if it is 0.81 it is tails For example: Enter a value for p-probability of heads (range:0.1):07 The random number generated is: 0.1323141393252708 Coin flip is is True /Tails is False: True This seems right but to get a better idea if we are getting heads 70% of the time Ips0.7) we would need to run this program multiple times (maybe 10, 100, 1000, 10cocoo). Task 5d Now copy your code that generates and displays the result 10 times in the same file. Remember to eeae anew random number each time but the probability should remain the same. For example: Enter a value for p-probability of heads range:01): 0.7 The random number generated is: 0.2159794929194504 Coin flip is (Heads is True /Tails is Falsel: True The random number generated is: 0.3992546587812352 Coin flip is (Heads is True /Tails is Falsel: True The random number generated is: 0.08083117189302635 Coin flip is (Heads is True /Tails is Falsel: True The random number generated is: 0.8140161780281813 Coin flip is (Heads is True /Tails is False: False The random number generated is: 0.8360287174855606 Coin flip is (Heads is True /Tails is False: False The random number generated is: 0.1548589912102123 Coin flip is (Heads is True /Tails is Falsel: True The random number generated is: 0.35722422645618834 Coin flip is (Heads is True /Tails is False: True The random number generated is: 0.44087390336969234 Coin flip is (Heads is True /Tails is Falsel: True Coin flip is (Heads is True /Tails is Falsel: True The random number generated is: 0.01588705564140891 Coin flip is is True /Tails is Falsel: True In my example I got 8 heads and 2 tails meaning (80% heads). This is fine as my sample size was quite small and it is just a probability. To get a better idea we could copy the code 1000 times but 10 was already tedious A better way would be to use a FOR laop, which we will cover next week. First create a file and save it as Week1_Task6. Write a program that takes as input a string representing a user's name. Your program should output the length of the name and the number of times each wowel accurs in it Hint: Check for uppercase and lowercase letters. Enter your name: CarolDanwers Length of your name is: 12 The number of a's are 2 The number of e'sare 1 The number of i's are The number of o'sare 1 The number of u's are 0Step 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