Homework assignment

This is my code, im having some issues when I input more than one dice for the program to add the dice together. ie. rolls one dice and then rolls another and adds them together. its for a probability graphic. I need one code that can do multiple variants of sides and quantity of dice. This code was provided by my professor and he just needs us to adjust it. thanks
import pygal
import random
results =
frequencies =
labels =
num_sides = input("Number of sides? ")
dice = input("Number of dice? ")
#intialize labels
for value in range(1, int(num_sides)+1):
labels.append(value)

#roll the dice alot
for roll_num in range(1000):
roll = random.randrange(1, int(num_sides)+1)
results.append(roll)
print(results[1:100])

#analyze the results
for value in range(1, int(num_sides)+1):
frequency = results.count(value)
frequencies.append(frequency)
print(frequencies)

Use pygal package to graph the frequencies

hist = pygal.Bar()
hist.title = “results of rolling " + dice + " dice with " + num_sides + " sides 1000 times”
hist.x_labels = labels
hist.x_title = “Result”
hist.y_title = “Frequency of Result”
hist.add(num_sides, frequencies)
hist.render_to_file(‘die_visual.svg’)

1 Like