-2

I'm trying to create this game but I'm stuck with this whole score counter lives and how to break the while loop.

player = input("Welcome! Let's play Rock, Paper, Scissors, Lizard, Spock. You have five lives. Press enter to start.")

from random import randint

t = ["rock", "paper", "scissors", "lizard", "spock"]

computer = t[randint(0,4)]

player = False

while player == False:

    lives = 5
    score = 0
    player = input("rock, paper, scissors, lizard, spock?")
    print("Computer plays",computer)
    if player == computer:
        print("Tie!")
        score + 1
    elif player == "rock":
        if computer == "paper":
            print("You lose!", computer, "covers", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "lizard":
            print("You win!", player, "crushes", computer)
            score + 2
        elif computer == "spock":
            print("You lose!", computer, "vaporises", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        else:
            print("You win!", player, "smashes", computer)
            score + 2
    elif player == "paper":
        if computer == "scissors":
            print("You lose!", computer, "cuts", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "lizard":
            print("You lose!", computer, "eats", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "spock":
            print("You win!", player, "disproves", computer)
            score + 2
        else:
            print("You win!", player, "covers", computer)
            score + 2
    elif player == "scissors":
        if computer == "rock":
            print("You lose...", computer, "smashes", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "spock":
            print("You lose!", computer, "smashes", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "lizard":
            print("You win!", player, "decapitates", computer)
            score + 2
        else:
            print("You win!", player, "cuts", computer)
            score + 2
    elif player == "spock":
        if computer == "lizard":
            print("You lose!", computer, "poisons", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "scissors":
            print("You win!", player, "smashes", computer)
            score + 2
        elif computer == "rock":
            print("You win!", player, "vaporises", computer)
            score + 2
        else:
            print("You lose!", computer, "disproves", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
    elif player == "lizard":
        if computer == "spock":
            print("You win!", player, "poisons", computer)
            score + 2
        elif computer == "rock":
            print("You lose!", computer, "crushes", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
        elif computer == "paper":
            print("You win!", player, "eats", computer)
            score + 2
        else:
            print("You lose!", computer, "decapitates", player)
            lives - 1
            if lives == 0:
                print("Your socre is", score)
                break
    else:
        print("That's not a valid play!")
    player = False
    computer = t[randint(0,4)]
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Hana
  • 1
  • 2

1 Answers1

0

A few suggestions to get your expected behavior of managing the score counter, lives and how to break the while loop.

  1. Move score and lives above the while-loop.
    Even though you are calculating their new values within the loop, their values will reset each loop if they are defined within the loop.
  2. Use increment and decrement operators for calculations.
    When doing calculations to assign new values, you'll want to save the result of the calculation back to the variable. Statements like score + 1 and lives - 1 have no effect on those variables until the result gets saved. You could change all score + 1 to score = score + 1 (or score +=1), and similarly change all lives - 1 to lives = lives - 1 (or lives -=1). See Behaviour of increment and decrement operators in Python for more detail.
  3. Remove all break statements.
    break is useful if and when you want to break out of the while loop, but since the game keeps playing (I assume, since you keep track of lives) until all lives are lost, then the loop will "break" when the condition lives > 0 is False.

After making these changes, your game should behave as expected.

Hope this helps.

BTW, good job on the game, I enjoyed playing and debugging it!