Make this code better

help me my code is not working and I don't know why

I must use a def function to create a code about a dice game where two people roll the dice and see who reaches 50 first. The game instructions are explained in the code

pigdicegame.py
# PIG DIE GAME # rules print("*********************************************") print("* WELCOME TO THE PIG DIE GAME *") print("*********************************************") print("To play enter r to roll the dice") print("The number you role will add onto your score") print("If you roll a 1 your score for that go will be 0") print("You can choose to end your go when you want") print("Race your opponent to 50") print(" ") #player 1 name name1 = input("Enter the name of player 1: ") name2 = input("Enter the name of player 2: ") #setting up variables import random play1 = "y" play2 = "y" player1_score = 0 player2_score = 0 #keep playing until someone reaches 0 while player1_score or player2_score != 50: def player1_turn(): #game code for player 1 print(" ") print("*****************************************") print(name1+"'s turn") print("*****************************************") print(" ") play1 = name1 while play1 == name1: roll = random.randint(1,6) # end go if roll = 1 if roll == 1: print("You rolled a 1. You have lost all your points for this round") player1_score = 0 play1 = "n" else: player1_score = player1_score + roll print("You rolled a", roll, "Your current score is",player1_score,) play1 = input("Enter your player name if you want to play again and any other character if you do not: ") return player1_score def player2_turn(): #game code for player 2 print(" ") print("*****************************************") print(name2+"'s turn") print("*****************************************") print(" ") play2 = name2 while play2 == name2: roll = random.randint(1,6) # end go if roll = 1 if roll == 1: print("You rolled a 1. You have lost all your points for this round") player2_score = 0 play2 = "n" else: player2_score = player2_score + roll print("You rolled a", roll, "Your current score is",player2_score,) play2 = input("Enter your player name if you want to play again (to get to 100) or any other character if you do not: ") return player2_score ## main program player1_points = player1_turn() player2_points = player2_turn() if player1_points == 50: print("Well done", name1,"you have won") elif player2_points == 50: print("Well done", name2,"you have won") else: print("Sorry, nobody reached 50 points. Nobody won!") /** * Add your code here * Any language, just go for it. */

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.