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.


Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS