'When round 1 ends I want it to loop 5 rounds then a break statement so it stops, then the if else ending

import random  
import time  

playervalue1 = 0 


playervalue2 = 0
password = input("Hello,welcome to Katrina's dice game \\nPlease enter the password to play")

if password == "ok":

    print("A wishful hello, welcome to Lordess' Katarina's Dice Game")
    time.sleep(3)
    print("Here are the rules of the game.")
    time.sleep(3)
    print("This game requires 2 players")
    time.sleep(3)
    print("After 5 rounds, the player with the highest score will automatically win Lord Katarina's Dice Game")
    time.sleep(3)
    print("The points rolled on each player’s dice are added to their score.")
    time.sleep(3)
    print("If both dice add up to an even number, then the player who rolled will increase by 10 extra")
    time.sleep(3)
    print("But, if both dice add up to an odd number, then you're in trouble, you will lose 5 points")
    time.sleep(3)
    print("If they roll a double, they get to roll one extra die and get the number of points rolled added to their score. ") 
    time.sleep(3)
    print("That's all the information you need to know,\nhave fun!!")
    time.sleep(2)
     
    input("Press enter when both players are ready to play")
     
    playername1 = input("Player 1 has joined, what's your name?\nType it in.")
    time.sleep(2)
    
    playername2 = input("Player 2 has joined, what's your name?\nType it in.")
    time.sleep(2)
    
    #(Round 1) Player 1 starts 
    print(playername1, "starts first (Round one)")
    
    input("Press the enter button to roll")
    
    print('"Rolling the dice"')
    time.sleep(3)
    
    player1diceroll1 = random.randint(1, 6)
    player1diceroll2 = random.randint (1, 6)
    
    player1total = player1diceroll1 + player1diceroll2
    
    print("Your roles are",player1diceroll1,"and",player1diceroll2,"which is equalivent to",player1total)
    time.sleep(2) 
    
    playervalue1 = player1total + playervalue1
    
    print(playername1, "you recieved", player1diceroll1, "and", player1diceroll2, "so you gained", player1total, "points!!")
    time.sleep(3)
    
    if player1diceroll1 == player1diceroll2:
       
        playervalue1 = 10 + playervalue1
        
        print("Oh Wow!", playername1,"you got two of the same number on both dice and acquired 10 extra points!\nYou get an additional roll!")
        time.sleep(2)
        
        input("Enter to roll again")
        
        print('"Rolling"')
        time.sleep(2)
        
        extraplayer1diceroll1 = random.randint(1, 6)
        extraplayer1diceroll2 = random.randint(1, 6)
        
        extraplayer1total1 = extraplayer1diceroll1 + extraplayer1diceroll2 
        
        print("Your rolls are",extraplayer1diceroll1,"and", extraplayer1diceroll2,"which is equivalent to",extraplayer1total1,playername1)
        time.sleep(2)
        
        playervalue1 = extraplayer1total1 + playervalue1
        
        print(playername1,"you recieved",extraplayer1diceroll1,"and",extraplayer1diceroll2,"so that means you gained",extraplayer1total1, "points!!")
        time.sleep(2)
        
        if (extraplayer1total1 % 2) == 0:
            
            playervalue1 = 10 + playervalue1
            
            print("You got an even number, so you achieve 10 additional points!")
            time.sleep(3)
            
            print("Your score by far is",playervalue1,playername1)
            time.sleep(2)
            
        else:
            
            playervalue1 = playervalue1 - 5
            
        if playervalue1 < 0:
                
                playervalue1 = 0
                
                print("You got an odd number, therefore you lose 5 points")
                time.sleep(3)
                
                print("Your score by far is",playervalue1,playername1)
                time.sleep(2)
                
        elif (player1total % 2) == 0:
        
            playervalue1 = 10 + playervalue1
        
            print("Wow! you achieved an even number, thereofore you acieved 10 additional points")
            time.sleep(3)
        
        else:
        
            playervalue1 = playervalue1 - 5
        
        if playervalue1 < 0:
            
            playervalue1 = 0 
            
            print("You got an odd number, therefore you lose 5 points")
            time.sleep(2)
            
            print("Your score by far is", playervalue1, playername1)
            time.sleep(2)
            
        else:
    
            print("You got an odd number, so you lose 5 points")
            time.sleep(2)
    
            print("Your score so far is", playervalue1, playername1)
            time.sleep(2)
            
    #(Round 1) Player 2 
    print(playername2, "plays now (Round one)")
    
    input("Press the enter button to roll")
    
    print('"Rolling the dice"')
    time.sleep(3)
    
    player2diceroll1 = random.randint(1, 6)
    
    player2diceroll2 = random.randint (1, 6)
    
    player2total = player2diceroll1 + player2diceroll2
    
    print("Your rolls are",player2diceroll1,"and",player2diceroll2,"which is equalivent to",player2total)
    time.sleep(2) 
    
    playervalue2 = player2total + playervalue2
    
    print(playername2, "you recieved", player2diceroll1, "and", player2diceroll2, "so you gained", player2total, "points!!")
    time.sleep(3)
    
    if player2diceroll1 == player2diceroll2:
       
        playervalue2 = 10 + playervalue2
        
        print("Oh Wow!", playername2,"you got two of the same number on both dice and acquired 10 extra points!\nYou get an additional roll!")
        time.sleep(2)
        
        input("Enter to roll again")
        
        print('"Rolling"')
        time.sleep(2)
        
        extraplayer2diceroll1 = random.randint(1, 6)
        
        extraplayer2diceroll2 = random.randint(1, 6)
        
        extraplayer2total1 = extraplayer2diceroll1 + extraplayer2diceroll2 
        
        print("Your rolls are",extraplayer2diceroll1,"and", extraplayer2diceroll2,"which is equivalent to",extraplayer2total1,playername2)
        time.sleep(2)
        
        playervalue2 = extraplayer2total1 + playervalue2
        
        print(playername2,"you recieved",extraplayer2diceroll1,"and",extraplayer3diceroll2,"so that means you gained",extraplayer3total1, "points!!")
        time.sleep(2)
        
        if (extraplayer2total1 % 2) == 0:
            
            playervalue2 = 10 + playervalue2
            
            print("You got an even number, so you achieve 10 additional points!")
            time.sleep(3)
            
            print("Your score by far is",playervalue2,playername2)
            time.sleep(2)
            
        else:
            
            playervalue2 = playervalue2 - 5
            
            if playervalue2 < 0:
                
                playervalue2 = 0
                
                print("You got an odd number, therefore you lose 5 points")
                time.sleep(3)
                
                print("Your score by far is",playervalue2,playername2)
                time.sleep(2)
                
    elif (player2total % 2) == 0:
        
        playervalue2 = 10 + playervalue2
        
        print("Wow! you achieved an even number, thereofore you acieved 10 additional points")
        time.sleep(3)
        
    else:
        
        playervalue2 = playervalue2 - 5
        
        if playervalue2 < 0:
            
            playervalue2 = 0 
            
            print("You got an odd number, therefore you lose 5 points")
            time.sleep(2)
            
            print("Your score by far is", playervalue2, playername2)
            time.sleep(2)
            
        else:
    
            print("You got an odd number, so you lose 5 points")
            time.sleep(2)
    
            print("Your score so far is", playervalue2, playername2)
            time.sleep(2)
            
    print("Round 1 ends!")
            
    
    #The Anticlimax
    print("The game has concluded.\nWhichever player achieved the highest score\nWINS!!")
    time.sleep(2)
    
    if playervalue1 == playervalue2:
        
        print("There is a tie between",playername1,"and",playername2,"with",playervalue1,"points")
        
        time.sleep(3)
        
        print("who ever roles the highest number wins it all")
        
        time.sleep(3)
        
        print(playername1,"is first")
        
        time.sleep(2)
        
        input("Enter to roll")
        print('"Rolling"')
        time.sleep(3)
        
        tieroll1player1 = random.randint (1, 6)
        
        tieroll2player1 = random.randint (1, 6)
        
        player1tie = tieroll1player1 + tieroll2player1
        
        print(playername1,"your rolls are",tieroll1player1,"and",tieroll2player1,"which is equal to",player1tie)
        
        time.sleep(3)
        
        print(playername2,"is next")
        
        time.sleep(3)
        
        input("Press enter to roll")
        print('"Rolling"')
        time.sleep(3)
        
        tieroll1player2 = random.randint (1, 6)
        
        tieroll2player2 = random.randint (1, 6)
        
        player2tie = tieroll1player2 + tieroll2player2
        
        print(playername2,"your rolls are",tieroll1player2,"and",tieroll2player2,"which is equal to",player2tie)
        
        time.sleep(3)
        
        print("The final winner is...")
        
        time.sleep(3)
        
        if player1tie > player2tie:
            print("Congrats",playername1,",you have won the dice game!")
            
            time.sleep(3)
            
            print("Thanks for playing!")
            exit()
            
        else:
            print("Congrats",playername2,",you have won the dice game!")
            
            time.sleep(3)
            
            print("Thanks for playing!")
            
            time.sleep(3)
            
            exit()
    
    if playervalue1 > playervalue2:
        print("Congrats",playername1,", you have won with",playervalue1,"points")
        
        time.sleep(3)
        
        print("Sorry",playername2,", you lost with",playervalue2,"points")
        
        time.sleep(3)
        
        print("Thanks for playing!")
        
        time.sleep(3)
        exit()
        
    else:
        print("Congrats",playername2,", you have won with",playervalue2,"points")
        
        time.sleep(3)
        
        print("Sorry",playername1,", you lost with",playervalue1,"points")
        
        time.sleep(3)
        
        print("Thanks for playing!")
        
        time.sleep(3)
        exit()

else:
print("sorry, the password seems to be incorrect.")
exit()

I am new to python so I tried my best with code but don't know how and where to loop and break.



Solution 1:[1]

you can wrap the base round in a function, that you'll call each time a round has begun. Because you don't need any parameters for this function to work, you can name it something like: def Main_Game_Loop():.

#this will work after you wrapped your main game loop
counter=0
while True: 
   Main_Game_Loop()
   counter+=1
if counter==5:
  break

The function and the counter will be below:

import random
import time


def Main_Game_Loop():
    playervalue1 = 0
    playername1 = ''
    playername2 = ''
    playervalue2 = 0
    player1total = 0
    password = input(
        "Hello,welcome to Katrina's dice game \nPlease enter the password to play")

    if password == "ok":

        print("Your score by far is", playervalue1, playername1)
        time.sleep(2)

    elif (player1total % 2) == 0:

        playervalue1 = 10 + playervalue1

        print(
            "Wow! you achieved an even number, thereofore you achieved 10 additional points")
        time.sleep(3)

    else:

        playervalue1 = playervalue1 - 5

    if playervalue1 < 0:

        playervalue1 = 0

        print("You got an odd number, therefore you lose 5 points")
        time.sleep(2)

        print("Your score by far is", playervalue1, playername1)
        time.sleep(2)

    else:

        print("You got an odd number, so you lose 5 points")
        time.sleep(2)

        print("Your score so far is", playervalue1, playername1)
        time.sleep(2)

    # (Round 1) Player 2
    print(playername2, "plays now (Round one)")

    input("Press the enter button to roll")

    print('"Rolling the dice"')
    time.sleep(3)

    player2diceroll1 = random.randint(1, 6)

    player2diceroll2 = random.randint(1, 6)

    player2total = player2diceroll1 + player2diceroll2

    print("Your rolls are", player2diceroll1, "and",
          player2diceroll2, "which is equivalent to", player2total)
    time.sleep(2)

    playervalue2 = player2total + playervalue2

    print(playername2, "you received", player2diceroll1, "and",
          player2diceroll2, "so you gained", player2total, "points!!")
    time.sleep(3)

    if player2diceroll1 == player2diceroll2:

        playervalue2 = 10 + playervalue2

        print("Oh Wow!", playername2,
              "you got two of the same number on both dice and acquired 10 extra points!\nYou get an additional roll!")
        time.sleep(2)

        input("Enter to roll again")

        print('"Rolling"')
        time.sleep(2)

        extraplayer2diceroll1 = random.randint(1, 6)

        extraplayer2diceroll2 = random.randint(1, 6)

        extraplayer2total1 = extraplayer2diceroll1 + extraplayer2diceroll2

        print("Your rolls are", extraplayer2diceroll1, "and", extraplayer2diceroll2,
              "which is equivalent to", extraplayer2total1, playername2)
        time.sleep(2)

        playervalue2 = extraplayer2total1 + playervalue2

        print(playername2, "you received", extraplayer2diceroll1, "and",
              extraplayer3diceroll2, "so that means you gained", extraplayer3total1, "points!!")
        time.sleep(2)

        if (extraplayer2total1 % 2) == 0:

            playervalue2 = 10 + playervalue2

            print("You got an even number, so you achieve 10 additional points!")
            time.sleep(3)

            print("Your score by far is", playervalue2, playername2)
            time.sleep(2)

        else:

            playervalue2 = playervalue2 - 5

            if playervalue2 < 0:

                playervalue2 = 0

                print("You got an odd number, therefore you lose 5 points")
                time.sleep(3)

                print("Your score by far is", playervalue2, playername2)
                time.sleep(2)

    elif (player2total % 2) == 0:

        playervalue2 = 10 + playervalue2

        print(
            "Wow! you achieved an even number, thereofore you achieved 10 additional points")
        time.sleep(3)

    else:

        playervalue2 = playervalue2 - 5

        if playervalue2 < 0:

            playervalue2 = 0

            print("You got an odd number, therefore you lose 5 points")
            time.sleep(2)

            print("Your score by far is", playervalue2, playername2)
            time.sleep(2)

        else:

            print("You got an odd number, so you lose 5 points")
            time.sleep(2)

            print("Your score so far is", playervalue2, playername2)
            time.sleep(2)

    print("Round 1 ends!")

    # The Anticlimax
    print("The game has concluded.\nWhichever player achieved the highest score\nWINS!!")
    time.sleep(2)

    if playervalue1 == playervalue2:

        print("There is a tie between", playername1, "and",
              playername2, "with", playervalue1, "points")

        time.sleep(3)

        print("who ever roles the highest number wins it all")

        time.sleep(3)

        print(playername1, "is first")

        time.sleep(2)

        input("Enter to roll")
        print('"Rolling"')
        time.sleep(3)

        tieroll1player1 = random.randint(1, 6)

        tieroll2player1 = random.randint(1, 6)

        player1tie = tieroll1player1 + tieroll2player1

        print(playername1, "your rolls are", tieroll1player1, "and",
              tieroll2player1, "which is equal to", player1tie)

        time.sleep(3)

        print(playername2, "is next")

        time.sleep(3)

        input("Press enter to roll")
        print('"Rolling"')
        time.sleep(3)

        tieroll1player2 = random.randint(1, 6)

        tieroll2player2 = random.randint(1, 6)

        player2tie = tieroll1player2 + tieroll2player2

        print(playername2, "your rolls are", tieroll1player2, "and",
              tieroll2player2, "which is equal to", player2tie)

        time.sleep(3)

        print("The final winner is...")

        time.sleep(3)

        if player1tie > player2tie:
            print("Congrats", playername1, ",you have won the dice game!")

            time.sleep(3)

            print("Thanks for playing!")
            exit()

        else:
            print("Congrats", playername2, ",you have won the dice game!")

            time.sleep(3)

            print("Thanks for playing!")

            time.sleep(3)

            exit()

    if playervalue1 > playervalue2:
        print("Congrats", playername1,
              ", you have won with", playervalue1, "points")

        time.sleep(3)

        print("Sorry", playername2, ", you lost with", playervalue2, "points")

        time.sleep(3)

        print("Thanks for playing!")

        time.sleep(3)
        exit()

    else:
        print("Congrats", playername2,
              ", you have won with", playervalue2, "points")

        time.sleep(3)

        print("Sorry", playername1, ", you lost with", playervalue1, "points")

        time.sleep(3)

        print("Thanks for playing!")

        time.sleep(3)
        exit()

    print("sorry, the password seems to be incorrect.")
    exit()


# This will be the main function, where you'll increment rounds
counter = 0
while True:
    Main_Game_Loop()
    counter += 1
    if counter == 5:
        break

This is untested, but you can play with it as you like. This is how i'd personally do it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1