I'm supposed to be writing code for the following problem:
A player rolls two six sided die. If the sum of the two dice is not seven, the sum is added to the player's total score and the player gets to roll again. When the player rolls a sum of seven, the game is over.
This is what I have so far:
def main():
dice1 = randrange(1, 7,)
dice2 = randrange(1, 7,)
roll = dice1 + dice2
score = 0
count = 0
while roll != 7:
count = count + 1
score = score + roll
if roll == 7:
break
print count
print score
main()
However, it just gives me an infinite loop when it should be rolling the die only until the sum of the die is seven.
How do I fix it?
if roll == 7: breakThat is taken care of bywhile roll != 7:print ( (lambda f: f (f, 0, 0, 0, __import__ ('random') ) ) (lambda f, r, c, s, i: (c, s) if r == 7 else f (f, i.randint (1, 6) + i.randint (1, 6), c + 1, s + r, i) ) )