{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Homework 4 - Chapter 9" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Due Date: Monday, September 29th no later than 11:59 p.m.\n", "- Partner Information: Complete this assignment individually\n", "- Submission Instructions: Upload your solution, entitled **YourFirstName-YourLastName-Homework4.ipynb** to the Canvas Homework 4 Dropbox.\n", "- Deadline Reminder: Once the submission deadline passes, Canvas will no longer accept your submission and you will no longer be able to earn credit. Thus, if you are not able to fully complete the assignment, submit whatever you have before the deadline so that partial credit can be earned." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Starting Code" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from datascience import *\n", "%matplotlib inline\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "No data set is needed for this assignment." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 1 - 3 Points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Dungeons & Dragons* is a tabletop role-playing game that relies on rolling a 20-sided die. Due to its rules-heavy nature, many mechanics modify these rolls. One of the most common is \"rolling with advantage.\" When rolling with advantage, a player rolls two 20-sided dice and uses the higher result. Write a function called **roll_with_advantage** that simulates a \"roll with advantage\" and run it 10,000 times, storing each final roll in an array. \n", "\n", "Use this data to create a table and display a histogram with a bin for each possible roll (1–20)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 2a - 2 Points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of the main uses for \"rolling with advantage\" is in attacking while in combat. In *Dungeons & Dragons*, an attack starts by rolling a 20-sided die (or in the case of \"rolling with advantage\", rolling two 20-sided dice and selecting the highest) and comparing the result to an enemy's Armor Class. If the number rolled is equal to or above an enemy's Armor Class, it hits! \n", "\n", "Using the results from your previous simulation, create a table showing the rolls that would hit a Kobold Warrior with an Armor Class of 14 and the number of times the attack would be successful." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 2b - 1 Point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is the probability of \"rolling with advantage\" and hitting the Kobold Warrior with an Armor Class of 14? Use Python and the table created in question 2a to perform this calculation. Print the probability in the following format: \n", "\n", "*The probability of hitting the Kobold Warrior is: XX.XX%*" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 3 - 2 Points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The second part of an attack in *Dungeons & Dragons* is rolling for damage. Each weapon has a designated *damage die* that determines the damage dealt to an enemy. Once again, there are many modifications that can be made to the *damage die*. One common modification is adding a set number to every roll, like +2. For example, if a 2 was rolled, the damage dealt by a weapon with a \"+2\" modifier would be 4. \n", "\n", "Create a function that makes a damage roll for a magic longsword by rolling an 8-sided die and then adding +2 to the result. Use this function 10,000 times, saving the data into a table. Display the first 8 entries of this table." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 4 - 2 Points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you have seen, in *Dungeons & Dragons*, attacking an enemy is broken into two rolls: first rolling to see if you hit an enemy (Questions 1 and 2), and then, if and only if you hit, rolling to see how much damage you do (Question 3). An enemy is defeated when you have reduced it to 0 Hit Points. \n", "\n", "To defeat an enemy in a single blow, a player must first see if they hit the monster, then make a damage roll that is equal to or above the enemy's Hit Points. Using the previous simulations and Python, find the probability of not only hitting the Kobold Warrior from Question 2 (when rolling with advantage), but also defeating it in a single blow with the magic longsword from Question 3. Assume the Kobold Warrior has 7 Hit Points. Print the probability in the following format: \n", "\n", "*The probability of hitting and defeating the Kobold Warrior in a single turn is: XX.XX%*" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.7" } }, "nbformat": 4, "nbformat_minor": 4 }