Okay new to python programing: Here is what I have, need some help. import rando
ID: 3758399 • Letter: O
Question
Okay new to python programing:
Here is what I have, need some help.
import random
numTimes = input("Enter number of games you would like to play: ")
total = 20
rolls = 0
while total !=numTimes:
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
dice3= random.randint(1, 6)
dice4 = random.randint(1, 6)
total = dice1+ dice2 + dice3 + dice4
rolls +=1001
print("Rolled was", dice1, dice2, dice3, dice4, "Tolal of",total)
print("It took", rolls, "rolls to get 20.")
This is what the lab is wanting:
How many rolls of a fair die does one need to accumulate at exactly 20 points? Of course one needs at least 4 rolls (as in 6 + 6 + 6 + 2 or 6 + 5 + 4 + 5) and at most 20 rolls (getting 20 times 1's in a row). However these situations are rather unlikely! Hence, we ask ourselves: what is the most likely number of times that one has to roll a die to get exactly 20 points? To answer this question, write a program that ask the user to simulate a number of games (e.g., 1000 games) and keeps frequency of the number of times that was needed to play one game. A game is defined as the number of times it is needed to get 20 points. Then print how many games the dice was rolled 4 times, 5 times, 6 times, 7 times …. up to 20 times out of the number of games that the . If for some reason in games it takes more than 20 times, use a variable to keep track of those games.
Hint: To simulate a rolling of a dice use the random module.
Here is my output:
('Rolled was', 4, 3, 6, 3, 'Tolal of', 16)
('It took', 1001, 'rolls to get 20.')
('Rolled was', 6, 1, 5, 4, 'Tolal of', 16)
('It took', 2002, 'rolls to get 20.')
('Rolled was', 5, 6, 3, 6, 'Tolal of', 20)
('It took', 3003, 'rolls to get 20.')
('Rolled was', 4, 3, 3, 1, 'Tolal of', 11)
('It took', 4004, 'rolls to get 20.')
('Rolled was', 6, 5, 5, 4, 'Tolal of', 20)
('It took', 5005, 'rolls to get 20.')
('Rolled was', 1, 6, 3, 1, 'Tolal of', 11)
('It took', 6006, 'rolls to get 20.')
('Rolled was', 4, 1, 2, 2, 'Tolal of', 9)
('It took', 7007, 'rolls to get 20.')
('Rolled was', 3, 1, 3, 4, 'Tolal of', 11)
('It took', 8008, 'rolls to get 20.')
('Rolled was', 6, 6, 3, 3, 'Tolal of', 18)
('It took', 9009, 'rolls to get 20.')
('Rolled was', 2, 2, 2, 5, 'Tolal of', 11)
('It took', 10010, 'rolls to get 20.')
Not what I'm looking for..... need some help please!
Explanation / Answer
CODE :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.