Answer to Question #281005 in Python for Joe

Question #281005

Using the random module, create a program that simulates rolling a pair of dice every time the user types “roll”. This can be done by generating numbers from 1-6 and displaying them on the screen. Keep allowing the user to type “roll” until the sum of the pair of dice rolled is 7. Once that happens, terminate the program.


1
Expert's answer
2021-12-20T09:59:47-0500
from random import randint




while True:
	roll = input().lower()
	if roll == 'roll':
		d1 = randint(1,6)
		d2 = randint(1,6)
		if (d1 + d2) == 7:
			print(d1, d2)
			break
		else:
			print(d1, d2)
	else:
		print("types 'roll' to roll the dice")
		continue

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS