dice

Is there a better way of printing my dice result in my dice roll function?

Is there a better way of printing my dice result in my dice roll function? Question: So I’m writing a dice_roll function for 2 dices to be rolled for my dice game project, currently I want to include the corresponding dice result in a dice format. Although the code does work, I was wondering if …

Total answers: 4

Rolling Dice Python

Rolling Dice Python Question: I’m trying to solve the following problem: From the input you will get a number. Find all the ways you can get this number when throwing two dice. Print the result as a list of tuples. In each tuple print the smaller number first. Sort the tuples by the first number. …

Total answers: 4

Rolling N Non-regular Dice in Constant Time

Rolling N Non-regular Dice in Constant Time Question: Say I have a non-regular dice defined by probabilities in a list that add up to one, e.g [0.1, 0.3, 0.4, 0.2]. I can use the following code to simulate rolling that dice n times: import random from collections import Counter def roll(dist, n): sides = [i …

Total answers: 1

Code works the long way but not as function

Code works the long way but not as function Question: I have a dice program which I have programmed two different ways. One way is long, that is I have repeated code, and it works fine. When I try and put the repeated code into a function, the program no longer works when a double …

Total answers: 2

Only allowing Integer input in python 3.3.2

Only allowing Integer input in python 3.3.2 Question: Hi i am trying to make the program only accept the numbers 0, 4, 6, and 12, and not allow anything else to be inputted. So far i have been successful in only allowing certain integers to be entered, however i am having trouble with not allowing …

Total answers: 4