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.
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
Comments
Leave a comment