--- About initial programming in python --- Make a procedure called many_times() that simulates a game of two dice. Your procedure should count how many times the dice were rolled until repeated numbers came out. (To throw two dice count as a single throw.) What should your procedure return? Should return the number of throws made and the two [equal] numbers chosen --- put the three values ​​into a tuple. Suppose your dice has 6 sides. Use the randint procedure of the random module to simulate the throw of a die. Documents for this procedure can be found at https://cutt.ly/dWsa2Rl. Note that there are restrictions on input values. Use randint, tuples and while to solve the problem. REMEMBER THAT THE THIRD ELEMENT IN THE TUPLE (THE NUMBER OF THROWS MADE) CANNOT BE 0 - Below is a print of my code that you should use as a basis to solve the challenge. My problem is that the third element of my tuple (number of dice rolls until repeated numbers appear) is returning 0 in some situations which is obviously wrong.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

--- About initial programming in python ---

Make a procedure called many_times() that simulates
a game of two dice. Your procedure should count how many times
the dice were rolled until repeated numbers came out. (To throw
two dice count as a single throw.) What should your procedure return? Should return the number of throws made and the two [equal] numbers chosen --- put the three values ​​into a tuple. Suppose your dice has 6 sides. Use the randint procedure of the random module to simulate the throw of a die. Documents for this procedure can be found at https://cutt.ly/dWsa2Rl. Note that there are restrictions on input values.
Use randint, tuples and while to solve the problem.

REMEMBER THAT THE THIRD ELEMENT IN THE TUPLE (THE NUMBER OF THROWS MADE) CANNOT BE 0

- Below is a print of my code that you should use as a basis to solve the challenge. My problem is that the third element of my tuple (number of dice rolls until repeated numbers appear) is returning 0 in some situations which is obviously wrong.

>>> how_many ()
(4, 4, 0)
>>> how many ()
(4, 4, 1)
>>> how many ()
(5, 5, 4)
>>> how many ()
(6, 6, 0)
>>> how many ()
(1, 1, 4)
>>> how many ()
(2, 2, 6)
import random
def how many () :
count = 0
while True:
x = random.randint (1, 6)
y = random.randint (1, 6)
if x == y:
break
else:
count+=1
return tuple ( (x,y, count))
>>>
Transcribed Image Text:>>> how_many () (4, 4, 0) >>> how many () (4, 4, 1) >>> how many () (5, 5, 4) >>> how many () (6, 6, 0) >>> how many () (1, 1, 4) >>> how many () (2, 2, 6) import random def how many () : count = 0 while True: x = random.randint (1, 6) y = random.randint (1, 6) if x == y: break else: count+=1 return tuple ( (x,y, count)) >>>
Expert Solution
Step 1

I have implemented the given requirements as above.

The issue is that there is no check for the value of count. There should be an "if" condition which checks if the value of count is greater than 0. Only in that case it will return the tuple.

The case where count is 0 is when the two dice rolled repeated number in the first throw which is to be ignored.

Code is as follows:

import random


def how_many():
    count = 0
    while True:
        x = random.randint(1, 6)
        y = random.randint(1, 6)
        if(x == y):
            break
        else:
            count = count + 1
    if(count > 0):
        return tuple((x, y, count))


a = how_many()
b = how_many()
c = how_many()
d = how_many()

print(a, "\t", b, "\t", c, "\t", d)
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY