I want this to keep track of each players turn including the AI. Not the numer of rolls but for each turn till the game ends. For example your turn ends when a 1 is rolled on either dice or both.

import sys
from random import randint
def game():
    playercount = 2
    maxscore = 100
    safescore = [0] * playercount
    player = 0
    score=0

    while max(safescore) < maxscore:
        if player == 0:
            rolling = 0
            if score < 17 and score + safescore[player] < maxscore:
                rolling = 1
        else:
            rolling = input("Player %i: (%i, %i) Rolling? (Y) "
                % (player, safescore[player], score)).strip().lower() in {'yes', 'y', ''}
        if rolling:
            rolled = randint(1, 6)
            rolled2 = randint(1, 6)
            print('  Rolled %i' % rolled)
            print('  Rolled %i' % rolled2)
            if rolled ==1 and rolled2 ==1:
                    print('  Snake Eyes!! your score is set to 0')
                    safescore[player] = 0    
                    player = (player + 1) % playercount

            elif rolled == 1:
                print('  Bust! you lose %i but still keep your previous %i'
                      % (score, safescore[player]))
                score, player = 0, (player + 1) % playercount
            elif rolled2 == 1:
                print('  Bust! you lose %i but still keep your previous %i'
                      % (score, safescore[player]))
                score, player = 0, (player + 1) % playercount


            else:
                score += rolled + rolled2
        else:
            safescore[player] += score
            if safescore[player] >= maxscore:
                break
            print('  Sticking with %i' % safescore[player])
            score, player = 0, (player + 1) % playercount




def wannaPlayAgain():
    play_again = input('Play again? y/n: ')
    if play_again == 'y':
        game()
    elif play_again == 'n':
        sys.exit()
    else:
        print("Answer is not valid.")


game()

wannaPlayAgain() 

Dani AI

Generated

Short summary and approach: you want to count completed turns for each participant (human and AI). A turn should be counted exactly once when control passes to the next player — i.e., when the current player busts (one or two 1s) or when they stick. Centralize that "end of turn" behavior so you don't forget a branch and accidentally double‑count.

A simple pattern: keep a per‑player list plus an overall counter, and call one small helper whenever a turn finishes. That helper should increment the right player's count, reset the round score, and advance to the next player. Example (use different names to fit your state):

turn_counts = [0] * playercount
total_turns = 0

def finish_turn(state):
    # state contains: 'player', 'round_score', 'turn_counts', 'total_turns'
    state['turn_counts'][state['player']] += 1
    state['total_turns'] += 1
    state['round_score'] = 0
    state['player'] = (state['player'] + 1) % len(state['turn_counts'])

Where to call it: invoke this helper at every place your code currently moves to the next player (snake eyes, single‑die busts, and after the player "sticks"). A key gotcha: if you detect a win immediately when a player sticks, decide whether that final (winning) turn should be counted — if yes, increment that player's counter before exiting the loop (or call the helper but be careful about checking the winner after the helper moves the player index).

Debugging tips: print the turn_counts and total_turns after each call to finish_turn while testing to verify no double increments. Treat the AI the same as a human player — the helper should be called when the AI stops rolling or gets a bust. This integrates ’s idea while keeping the logic tidy and robust for both human and AI turns.

first I would add an object to take care of holding the player's turn counts:

playerTurns = [0 for x in range(playercount)]]

And then, wherever a player's turn ends(Keep track of which player is which as well...) simply increment the proper count:

if turnEnds:
    playerTurns[player] += 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.