Question

Take the python code below and modify it to support multiple dice with multiple sides.

The input will need to be modified to ask an additional question "How Many Dice? ". Note: When you have multiple dice you are adding the dice together (i.e. roll 1 + roll 2 + ...). Please send me your python code and svg files. Note: Remember to install the pygal package. Thonny -> Tools -> Manage Packages. Due 3/3. Read Part 2 of "How Computers Work".

import pygal import random results = [] frequencies = [] labels = [] num_sides = input(Number of sides?) #intialize labels

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import pygal
import random
results=[]
frequencies=[]
labels=[]
roll=0
sum_of_rolls=0
num_sides=input("Number of sides??")
num_die=input("how many die??") #take input for number of dice


#minimum value and max value for for loop changes
for value in range(1*num_die,int(num_sides)*num_die+1):
labels.append(value)


for roll_num in range(1000):
sum_of_rolls=0

#number of rolls made= num_die times and add them to sum_of_rolls
for d in range(num_die):
roll=random.randrange(1,int(num_sides)+1)
sum_of_rolls=sum_of_rolls+roll
results.append(sum_of_rolls)

print(results[1:100])

#minimum value and max value for for loop changes
for value in range(1*num_die,int(num_sides)*num_die+1):
frequency=results.count(value)
frequencies.append(frequency)
print(frequencies)

hist=pygal.Bar()
hist.title = "results of rolling "+num_die+"dice with "+num_sides+" sides each for 1000 times"
hist.x_labels=labels
hist.x_title="Result"
hist.y_title="Frequency of Result"
hist.add(len(frequencies),frequencies)
hist.render_to_file('die_visual.svg')

-----------------------

Add a comment
Know the answer?
Add Answer to:
Take the python code below and modify it to support multiple dice with multiple sides. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to write python code that is a dice rolling function that generates random numbers. The...

    How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...

  • Goal: Translate this Python script into Java: magic8ball.py Deliverable: Magic8Ball.java Grading Breakdown: Functionality: 35; Source code...

    Goal: Translate this Python script into Java: magic8ball.py Deliverable: Magic8Ball.java Grading Breakdown: Functionality: 35; Source code comments: 5; Indentation: 5; Properly Submitted: 5. Example: Here is a Java class that simulates the roll of a single die: import java.util.Random; public class DiceRoll { public static void main(String[ ] args) { Random r = new Random( ); int roll1 = r.nextInt(6) + 1; int roll2 = r.nextInt(6) + 1; System.out.println("Sum of rolls:" + (roll1 + roll2)); } } Here is the...

  • given code: assignment: use python to extend the given code to create an output similar to...

    given code: assignment: use python to extend the given code to create an output similar to the one in the black box please explain the final code import random HALMst N in = int(input('Enter Total Number of Cards: ") NM in NOON A = [] B [] E - [] D = [] E = [] for i in range(1, n+1): A.append(i) D.append(i) E.append(i) for j in range(n): 8.append(random.choice(D)) D.remove(B[5]) C.append(random.choice(E)) E.remove(C[j]) c= 0 for k in range(n): if (Brkl...cikl):...

  • Python help! I need help getting my code to increment the value. It keep calculating the...

    Python help! I need help getting my code to increment the value. It keep calculating the range over the same number and not moving up! this is the question Write a program named q1() that prompts the user for the starting and ending distance in Kilometers (km), and an increment value. It should then print the conversion table showing values for Kilometers, Miles (M) and Feet (ft). Each value should be displayed as they are calculated. and this is the...

  • JAVA. Rolling a die 60,000 times with streams. Modify the code below to capture the time before a...

    JAVA. Rolling a die 60,000 times with streams. Modify the code below to capture the time before and after evaluating the stream pipeline (use package java.time which contains instant and duration). Then calculate the difference between the Instants to determine the total time. Use Instant's static method now to get the current time. To determine the difference between two Instants, use class Duration's static method between, which returns a Duration object containing the time difference. Duration provides methods like toMillis...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [...

    convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...

  • Please answer this question using python programming only and provide a screen short for this code....

    Please answer this question using python programming only and provide a screen short for this code. Homework 3 - Multiples not less than a number Question 1 (out of 3) This homework is a SOLO assignment. While generally I encourage you to help one another to learn the material, you may only submit code that you have composed and that you understand. Use this template to write a Python 3 program that calculates the nearest multiple of a number that...

  • using python in eclipses Question I am attempting to solve My attempt... 1. Add a new...

    using python in eclipses Question I am attempting to solve My attempt... 1. Add a new module named twenty_questions_class to the package library. 2. Define a class named TwentyQuestions in the module with an instance constructor and a method. a. The instance constructor _init is used to create an instance of the TwentyQuestions class with a value for the RANGE. b. The method named play lets the user play the game. For example, I am thinking of a secret number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT