Question

Write a python function to solve the following problem. Roll N(amount of) fair six-sided dice. The...

Write a python function to solve the following problem.

Roll N(amount of) fair six-sided dice. The sum of the face values is M. Write a python function to determine how many different ways can you roll the dice given M and N.

For example, if N=2 and M=7 the answer is 6, because you can roll this dice in these 6 different ways: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1)

Another example: if N = 3 and M = 9 the answer is 25

Another example: if N = 8 and M = 24 the answer is 98813

def roll_dice(N,M):

result = []

return len(result)

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

def roll_dice(N, M):

  faces = 6

  poss=[[0]*(M+1) for j in range(N+1)]

  for j in range(1,min(faces+1,M+1)):

    poss[1][j]=1

    

  for a in range(2,N+1):

    for b in range(1,M+1):

      for c in range(1,min(faces+1,b)):

        poss[a][b]+=poss[a-1][b-c]

  

  return poss[-1][-1]

print(roll_dice(2,7))

print(roll_dice(3,9))

print(roll_dice(8,24))

# Please up vote. Happy Learning

Add a comment
Know the answer?
Add Answer to:
Write a python function to solve the following problem. Roll N(amount of) fair six-sided dice. 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
  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values...

    The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...

  • Write a Code in Java or Python, for the following scenario(s): Consider three six-sided dice, and...

    Write a Code in Java or Python, for the following scenario(s): Consider three six-sided dice, and let random variable Y = the value of the face for each. The probability mass of function of Y is given by the following table: y 1 2 3 4 5 6 otherwise P(Y=y) 0.35 0.30 0.25 0.05 0.03 0.02 0 Roll the three dice and let random variable X = sum of the three faces. Repeat this experiment 50000 times. Find the simulated...

  • 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:...

  • The final answer is 4.472 2. You roll two fair, six-sided dice. Let X be the...

    The final answer is 4.472 2. You roll two fair, six-sided dice. Let X be the number on the first die. Let Y be the number on the second die. Calculate E[max(X,Y)], the expected value of the larger of the two numbers. There are several ways you can do this. You should try to do this by applying 2D LOTUS to the joint distribution of X and Y , which is extremely simple. To check your answer, you can use...

  • Consider the following game: You roll six 6-sided dice dı,..., de and you win if some...

    Consider the following game: You roll six 6-sided dice dı,..., de and you win if some number appears 3 or more times. For example, if you roll: (3,3,5,4,6, 6) then you lose. If you roll (4,1,3,6,4,4) then you win 1. What is the probability that you win this game? Hint: The answer is 119/324

  • Practice: • function • loops • if condition • random Roll a dice many times, you...

    Practice: • function • loops • if condition • random Roll a dice many times, you will see that each face value will count of roughly 1/6 • write a function • roll a dice once, return value will be 1-6, • use your functin I call your function 6000 times • count how many times of face 1 • count how many times of face 2 • print out the numbers of total face 1, 2, ..., 6 you...

  • Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling...

    Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling two six sided dice. That is, each dice has a number 1 through 6 on one of its sides. The return value is a list which contains tuples. Each tuple represents a possible dice roll of two dice. Card Deck Create a function named build_deck that returns a full deck of cards. The cards are created by a rank and a suit (e.g. 2♡)....

  • Complete each problem separately and perform in python. 1. Create a script that will roll five...

    Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...

  • This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no input...

    This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice This problem investigates how...

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