What is the best way to add up dice in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the best way to add up dice in python?

As a first project in python, I am having user input to tell me how many d4's, d6's, d8's, d10's, and d12's are being rolled, then finding the probability of each outcome. I later plan to graph the probabilities using matplotlib, but I am stuck trying to find the number of potential outcomes for each value. for-loops are a no go because the number of dice is not set. I have tried using lists with the values for each dice, but can't figure out how to generate names for variables. Any suggestions would be appreciated.

30th Jul 2019, 5:56 PM
Brenden Kelly
Brenden Kelly - avatar
3 Answers
30th Jul 2019, 10:04 PM
Steven M
Steven M - avatar
+ 2
You can save the value that the user inputs and let the loop run until that number. You can let a for loop run until a value that is stored in a variable.
30th Jul 2019, 6:02 PM
Dragonxiv
Dragonxiv - avatar
0
Sorry if I wasn't clear. I am simulating a large number of dice of different values being rolled, imagine high level D&D. I think I am going to try Class Dice(MaxVal, Val=1)#acts as a dice with max roll then test every value of the first dice, increment the second dice, and repeat. This info can be stored in a list.
30th Jul 2019, 6:40 PM
Brenden Kelly
Brenden Kelly - avatar