How to get out put from this code?

import random

def play_game():
    turn=1
    score=0
    game_over=False
    while not game_over:
        turn,score,game_over=take_turn(turn,score,game_over)
    print()
    print("game over")

def take_turn(turn,score,game_over):
    print("turn",turn)
    score_this_turn=0
    turn_over=False
    while not turn_over:
        choice=input("roll or hold? (r/h):")
        if choice=="r":
            turn,score,score_this_turn,turn_over= \
               roll_die(turn,score,score_this_turn)
        elif choice=="h":
            turn,score,turn_over,game_over=hold_turn(turn,score,score,score_this_turn)
        else:
            print("invalid choice try again")
    return turn,score,game_over

def roll_die(turn,score,score_this_turn):
    die=random.randint(1,6)
    print("die",str(die))
    if die==1:
       score_this_turn=0
       turn+=1
       print("turn over no score.\n")
       turn_over=True
    else:
       score_this_turn+=die
       turn_over=False
    return turn,score,score_this_turn,turn_over

def hold_turn(turn,score,score_this_turn):
    print("total score:",score_this_turn)
    score+=score_this_turn
    print("total score",score,"\n")
    turn_over=True
    game_over=False
    if score>=20:
        print("you finish in",turn,"turns")
        game_over=True
        return turn,score,turn_over,game_over
    turn+=1
    return turn,score,turn_over,game_over

Please post your code in readable Python by making use of the </> icon in the menu bar atop the text box in which you are typing.

1 Like