Question

Using Python: Write a program which asks for a number of dice and the number of...

Using Python:

Write a program which asks for a number of dice and the number of sides on the dice (you may assume all dice have the same number of sides). Your program should then roll the dice 100 times and print the average value rolled. For example:

If I choose one 6-sided die, the possible rolls are between 1 and 6. However, if I choose two 6-sided dice, the possible rolls are between 2 and 12. If I choose three 12-sided dice, the possible rolls are between 3 and 36.

For simplicity, you may assume the dice can have any positive number of sides greater than 1. If the user choose and invalid number of dice (less than 1) or an invalid number of sides (less than 2), your program should re-prompt the user for valid values.

Homework Answers

Answer #1
import random
n = int(input("Enter number of dice: "))
while(n<1):
    print("Invalid input.. Please try again")
    n = int(input("Enter number of dice: "))
sides = int(input("Enter number of sides: "))
while(sides<2):
    print("Invalid input.. Please try again")
    sides = int(input("Enter number of sides: "))
minValue = n
maxValue = n*sides
total = 0
for i in range(100):
    total += random.randint(minValue,maxValue)
print("Average value rolled:",total//100)

Know the answer?
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
Similar Questions
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py...
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py that has the following functions in the following order: in python Write a function roll that takes an int n and returns a random number between 1 and n inclusive. Note: This function represents a n sided die so it should produce pseudo random numbers. You can accomplish this using the random module built into python.         (3 pts) Write a function scoreRound that...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Problem 4)A simplified version of the dice game 10,000 is played using 5 dice. The player...
Problem 4)A simplified version of the dice game 10,000 is played using 5 dice. The player rolls the 5 six-sided dice, each 1 that is rolled, the player achieves a score of 100. A) How many possible ways are there to roll i l's over these 5 dice? (Hint: use combinations) B) The probability of any one dice rolling to a value of 1 is 1/5 (since each dice has six sides). Use the binomial probability distribution. Calculate the probability...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
On python how do i prompt a user to enter a number but the program is...
On python how do i prompt a user to enter a number but the program is only inclusive for a certain range. For example, prompting the user to enter a number (inclusive with integers between 0 and 10)?
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT