python - How can I make the program restart? -


there seems error in restarting program, not restart properly. asks if want play again asks name of players tells goal restarts itself.

import random, time  #variables die1 = 0 die2 = 0 goal = 0    tries1 = 0  tries2 = 0 sum = 0 sum2 = 0 choice = "y"  while choice == "y": #asking player's names     player1 = input("what name, player1?")     player2 = input("what name, player2?")  #the "goal"     goal = random.randrange(5) + 1     print("the goal is:", goal)  #first while loop first die rolled first player     while die1 != goal:         die1 = random.randrange(5) + 1         time.sleep(1)         print(player1, "your roll is:", die1)         tries1 = tries1 + 1         sum = sum + die1         time.sleep(1.5)         print("your sum is:", sum) #second while loop second die rolled second player         while die2 != goal:         die2 = random.randrange(5) + 1         time.sleep(1)         print(player2, "your roll is:", die2)         tries2 = tries2 + 1         sum2 = sum2 + die2         time.sleep(1.5)         print("your sum is:", sum2)          time.sleep(2)  #the statement @ end of game         print("\n\n""player", "\t\t", "goal", "\t\t", "# of rolls","\t\t", "sum of rolls", "\n", player1, "\t\t", goal, "\t\t", tries1,"\t\t\t", sum, "\n", player2, "\t\t", goal, "\t\t", tries2, "\t\t\t", sum2)         choice = input("would play again?: (y) or (n)")         goal = 0         tries1 = 0         tries2 = 0         sum = 0         sum2 = 0         break 

it's because @ end of program breaking out of main while loop no matter what. should surround if statement using choice variable. last statement inline while when second player rolls therefore executed in loop. fix going need reduce indentation executed @ end of game. tries1 variable indented out space python throw form of syntax error @ well.