WebNovels

Chapter 5 - code 5

import random

# Options

choices = ["rock", "paper", "scissors"]

# Scores

player_score = 0

computer_score = 0

# Number of rounds

rounds = 3

print("Welcome to Rock, Paper, Scissors!")

print("Best of 3 rounds wins.\n")

for round_num in range(1, rounds + 1):

print(f"Round {round_num}")

player = input("Choose rock, paper, or scissors: ").lower()

computer = random.choice(choices)

if player not in choices:

print("Invalid choice. You lose this round!")

computer_score += 1

else:

print(f"Computer chose: {computer}")

if player == computer:

print("It's a tie!")

elif (player == "rock" and computer == "scissors") or \

(player == "paper" and computer == "rock") or \

(player == "scissors" and computer == "paper"):

print("You win this round!")

player_score += 1

else:

print("Computer wins this round!")

computer_score += 1

print(f"Score -> You: {player_score}, Computer: {computer_score}\n")

# Final result

if player_score > computer_score:

print("🎉 You win the game!")

elif player_score < computer_score:

print("😢 You lose the game!")

else:

print("🤝 It's a tie game!")

More Chapters