Question: Language: Python 3.6 Program: PyCharm Interpreter: Anaconda --- Purpose: To practice combining conditionals and loops Degree of Difficulty: Tricky. You'll need to use everything you've
Language: Python 3.6
Program: PyCharm
Interpreter: Anaconda
---


Purpose: To practice combining conditionals and loops Degree of Difficulty: Tricky. You'll need to use everything you've learned so far There are some problems in science and mathematics in which a particular process can be described simply and precisely, but actually doing the math to solve it perfectly is very tedious (and for large versions of the problem, perhaps impossibly tedious). One powerful tool we can use in such cases is simulation where we simulate the process itself many, many times and just count the results. This is especially useful when the process involves randomness of some kind. You'll practice writing such a simulation for this question. The simulation A Koffing is on the loose, and is about to poison the city with its noxious gas! Only Pikachu can save the day. Pikachu will have to defeat the Koffing in a single blow 1 before the Koffing can release its fumes. It turns out that the Koffing has a fixed amount of health, and that we can simulate Pikachu's attack by rolling a bunch of 6-sided dice. In Python, we'll roll" a die by importing the random module and using the randrange) method to generate a random number from 1 to 6. Here are the rules for the dice roll: Each 6 rolled on the dice deals 1 damage . Rolling a 1 on the dice does nothing by itself. But if exactly two 1s are rolled, they deal 5 damage (it's super effective!) HOWEVER, if three or more 1s are rolled, the ENTIRE ATTACK is cancelled and deals zero damage If the total damage from the roll equals or exceeds the Koffing's health, then it is defeated and Pikachu has saved the city Example 1: The Koffing has 3 health. Pikachu rolls 6 dice and gets (1, 2, 3,4,5, 6). There is only one 6 so the total damage is 1, which is not enough to defeat the Koffing Example 2: The Koffing has 3 health. Pikachu rolls 6 dice and gets (1, 2, 3,1, 5, 5). There are no 6s, but there are two 1s, which together deal 5 damage. The Koffing is defeated! Example 3: The Koffing has 3 health. Pikachu rolls 6 dice and gets (1, 1. 1 6, 6, 6). There are at least three 1s, so the entire attack deals no damage and the Koffing is not defeated. The goal for your simulation is to determine how likely it is that the Koffing will be defeated with a givern amount of health and dice. You'll do this by simulating the procedure outlined above 1000 separate times and counting the results. Conceptually. it's no different than if you sat at your desk and just physically rolled the dice yourself and then wrote down the result, and then repeated that process another 999 times. Sample Run: Console output Sample input and output (input typed by the user is shown in green text: How many dice does Pikachu have? 6 How much health does Koffing have? 3 Pikachu rolled 6 dice against a Koffing with 3 health. Pikachu won 284 out of 1000 times ( 28.4 %)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
