208k views
2 votes
Write a code segment that uses a while loop and the random.randint and print functions to generate and print random integers between or including 1 and 6 until a 6 is rolled. The code segment must also count the number of times the number 3 was generated and display that value once at the very end of its execution.

User AlBaraa Sh
by
4.0k points

1 Answer

4 votes

In python:

import random

i = 0

while True:

w = random.randint(1,6)

if w == 6:

break

elif w == 3:

i += 1

print(w)

print(f"3 was generated {i} times")

I don't exactly know how you want the output but you should be able to modify my code according to your needs. I hope this helps!

User Lita
by
5.2k points