so i was just making a python rock paper scissors game and it has a score limit of 5. so if either the user or the computer reaches the score of 5, the game will print the person won or the computer won respectively. but it prints it if the computer wins only and also when the user wins the game doesn’t end and it doesn’t print that the user won. pls help me this is my code:
import random
user_score = int(0)
pc_score = int(0)
score_limit = 5
while user_score != score_limit or pc_score != score_limit:
user_guess: str = input(str("pls enter your guess, rock/paper/scissors:")).lower()
my_list = "rock", "paper", "scissors"
pc_guess = random.choice(my_list)
print("the computer chose", pc_guess)
if pc_guess == "rock" and user_guess == "rock":
print ( "Tie!!" )
if pc_guess == "paper" and user_guess == "paper":
print ( "Tie!!" )
if pc_guess == "scissors" and user_guess == "scissors":
print ( "Tie!!" )
if pc_guess == "paper" and user_guess == "rock":
print ( "the computer scores" )
pc_score = pc_score + 1
print ( "the pc score is:", pc_score )
if pc_guess == "rock" and user_guess == "paper":
print ( "yay u scored" )
user_score = user_score + 1
print ( "the user score is:", user_score )
if pc_guess == "rock" and user_guess == "scissors":
print ( "the computer scored" )
pc_score = int ( pc_score ) + 1
print ( "the pc score is:", pc_score )
if pc_guess == "scissors" and user_guess == "rock":
print ( "yay u scored" )
user_score = user_score + 1
print ( "the user score is:", user_score )
if pc_guess == "paper" and user_guess == "scissors":
print ( "yay u scored" )
user_score = user_score + 1
print ( "the user score is:", user_score )
if pc_guess == "scissors" and user_guess == "paper":
print ( "the computer scored" )
pc_score = int ( pc_score ) + 1
print ( "the pc score is:", pc_score )
pc_guess = random.choice ( my_list )
if user_score == score_limit:
print("yay congrats u won")
elif pc_score == score_limit:
print("oopsies, the computer won, better luck next time")
break
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
This looks quite good! You just need to move the last
if else
statement out of the previousif
statement like this:Hope that this helps! Regards, Bobby