The intention of this code is to run in a loop until a specified amount of turns or until I roll snake eyes(both die are = 1). I am not entirely sure what specifically is not working in my code so far.
import random
def play_game(rolls, win_turns):
win_turns = 0
rolls = []
i = 2
for _ in range(2):
roll = random.randint(1, i)
rolls.append(roll)
win_turns= win_turns 1
i = i 2
if roll in rolls == 2:
return win_turns
CodePudding user response:
You have a number of problems here. Your "loop" only picks the two dice -- you don't loop until a loss. The "roll in rolls == 2" doesn't mean anything. This basically does what you ask:
import random
def play_game(turns):
win_turns = 0
for _ in range(turns):
die = random.randint(1,6), random.randint(1,6)
print("Roll:", die )
if sum(die) == 2:
break
win_turns = 1
return win_turns
print("Wins:", play_game(10))