Click here to Skip to main content
15,609,968 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have generated the number between 1 to 6 using the randint() but now I want to know how many times the 66 are generated.

Is list needed to be used. Just dont know how to start checking the number.

What I have tried:

from random import *
trial = randint(1, 6)
print(trial)
counter = 0

last_dice = randint(1, 6)
print(last_dice, end='')

for i in range(trial-1):
    new_dice = randint(1, 6)
    print(new_dice, end='')
    if last_dice == 6 and new_dice == 6:
        last_dice = new_dice
        counter += 1

print()
print(counter)
Posted
Updated 30-Apr-21 1:45am
v2

If all you are looking for is "how many double sixes are thrown?" then it's pretty simple - you don't have to "remember" all the throws at all, so no list is needed.

Instead, think how you would do it manually with one die.
You'd have an area on the paper for marking each time you got a double six, and you'd remember if the last throw was a six.
Each time you threw, you'd check if it was a six.
If it wasn't, ignore it.
If it was, you'd check if the last one was and increase your "double sixes" count by one.
Then you'd throw again for the next one and repeat until you'd had enough.

So in code you want to do exactly the same thing!

Make sense?

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
v2
Comments
CPallini 30-Apr-21 10:54am    
5.
Quote:
I have generated the number between 1 to 6 using the randint() but now I want to know how many times the 66 are generated.

Think about the problem, what do you need to solve the problem by hand?
You do,'t need to keep a list of all dice drawing, all you need is to keep track of last dice.
Python
draw NewDice
If LastDice is 6 and NewDice is 6 then it is a 66
LastDice takes the value of NewDice
and Loop

[Update]
Try this change
Python
for i in range(trial-1):
    new_dice = randint(1, 6)
    print(new_dice, end='')
    if last_dice == 6 and new_dice == 6:
        counter += 1
    last_dice = new_dice

print()
print(counter)

Advice: try to draw more than 6 dices, at least for testing purpose. 36 draw of dice gets a reasonable odd to get a couple of 66.
[Update]
Quote:
I increased the no of draws to 100 and 666 are also being counted as 2 in counter....

When you encounter a 66, After increment counter, change the new_dice to another value to make sure it will not be used again.
 
Share this answer
 
v5
Comments
Francis Sadiq 30-Apr-21 7:33am    
Thank... its worked but new problem. I increased the no of draws to 100 and 666 are also being counted as 2 in counter.... please help me with that. thanks
Richard MacCutchan 30-Apr-21 7:46am    
See my answer below.
Patrice T 30-Apr-21 10:20am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
CPallini 30-Apr-21 10:55am    
5.
Patrice T 30-Apr-21 11:01am    
Thank you
You are making this more complicated than necessary. All you need is to throw two dice and check the values:
Python
for i in range(trial): # the value of trial will need to be fairly large to ensure a good distribution.
    die1 = randint(1, 6)
    die2 = randint(1, 6)
    if die1 == 6 and die2 == 6:
        counter += 1
 
Share this answer
 
Comments
Patrice T 30-Apr-21 10:18am    
I think the question is for using only 1 dice.
Richard MacCutchan 30-Apr-21 11:10am    
That is not what the question says.
Patrice T 30-Apr-21 11:31am    
In first version of question, OP was building a list of draws, then scanning the list (with i and i+1) in search of consecutive 66.
That is pretty close to using 1 dice only.
Richard MacCutchan 30-Apr-21 11:35am    
But I was answering this question, which specifically asks for the number of double sixes in a set of throws.
Patrice T 30-Apr-21 11:43am    
Read again the title: "How do I get to know the double 66 in randomly generated number to certain lenth"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900