Search code examples
pythonaddition

How to add points to a player in python


Essentially I've made a best-of-three RPS game and wanted to count how many points a player has.

Code

import random
import sys

pc_points = 0
player_points = 0

acceptance_of_death = input('welcome to the possibly winable RPS game. Do you dare to attempt this quite possible feat?\nAnswer yes or no\n')


while True:
    if acceptance_of_death =='yes':
        you_will_lose = input('Ok then. Rock, paper, or scissors?\n')

    else:
        print('Ok, your loss.\n')
        sys.exit()

    rps_list = ('rock','paper','scissors')

    result = random.choice(rps_list)

    if result == you_will_lose.lower():
        print("that's a tie, try again.")
        print(player_points)
        print(pc_points)

    elif result == 'rock' and you_will_lose.lower() == 'scissors':
        print('PC chooses rock. You lose.')
        pc_points = +1
        print(player_points)
        print(pc_points)

    elif result == 'scissors' and you_will_lose.lower() == 'paper':
        print('PC chooses scissors. You lose.')
        pc_points = + 1
        print(player_points)
        print(pc_points)

    elif result == 'paper' and you_will_lose.lower() == 'rock':
        print('PC chooses paper. You lose.')
        pc_points = + 1
        print(player_points)
        print(pc_points)

    else:
        print("you win! don't get too excited I made this in a very miniscule amount of time.")
        player_points = + 1
        print(player_points)
        print(pc_points)

    if player_points == 3:
        print('You win. Feel accomplished!')
        sys.exit()

    if player_points == 3:
        print('You lose. Pathetic!')
        print(player_points)
        print(pc_points)
        sys.exit()

I used player_points and pc_points in order to count the points that a player has gained. I tried adding points by player_points = + 1 but that only goes up to player_points = 1 and stays at that value, never increasing over 1.

How can I increase the count higher than 1?


Solution

  • Its +=, not =+.

    You use

    x += 1
    

    to increment x by 1. You use

    x = + 1
    

    to assign that x = 1