Past Lesson Note

This note is from 9 months ago. You're viewing content from a previous lesson.

Daily Note for August 28, 2025 Past Lesson

We are going to review our daily notes

We are going to review our code.

We are going to review the random module including:

random.randint
random.choice

Problem Statement

Write a program that lets the user play Rock, Paper, Scissors against the computer.
The computer should randomly choose one of the three options.
The user should enter their choice.
The program should decide who wins and display the resu

Step-by-Step Instructions

  1. Import the random module (to let the computer make a random choice).

  2. Define the possible moves: "rock", "paper", "scissors".

  3. Ask the user to type their move.

  4. Generate the computer’s move randomly.

  5. Compare choices using if/elif/else.

    • Rock beats scissors.

    • Scissors beat paper.

    • Paper beats rock.

    • Same choice = tie.

  6. Display the result clearly.

  7. (Extension) Ask the user if they want to play again.

Example Run

Welcome to Rock, Paper, Scissors!

Enter your move (rock, paper, scissors): rock
Computer chose: scissors
You win! Rock crushes scissors.

Play again? (yes/no): yes

Enter your move (rock, paper, scissors): paper
Computer chose: paper
It’s a tie!

Play again? (yes/no): no
Thanks for playing!

 

Success Criteria

  • Program accepts user input.

  • Program generates a random move for the computer.

  • Program correctly determines the winner.

  • Program repeats until the user chooses to quit.

 

 

"""
Rock, Paper, Scissors – Beginner Reference Implementation (no functions)

Learning goals:
- Input / output
- Random choice
- if / elif / else (decision making)
- Loops (play again until quit)

How to run:
$ python rps_simple.py
"""

import random  # we need this to let the computer choose randomly

# Define the valid moves
valid_moves = ["rock", "paper", "scissors"]

# Keep track of the score
wins = 0
losses = 0
ties = 0

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

# Main game loop: keep playing until the player chooses to stop
while True:
    # -----------------------
    # Step 1: Get player's move
    # -----------------------
    player = input("Enter your move (rock, paper, scissors): ").strip().lower()

    # Allow short versions (r, p, s)
    if player == "r":
        player = "rock"
    elif player == "p":
        player = "paper"
    elif player == "s":
        player = "scissors"

    # If input is not valid, ask again
    if player not in valid_moves:
        print("Invalid choice. Please type 'rock', 'paper', or 'scissors' (or r/p/s).\n")
        continue  # restart the loop

    # -----------------------
    # Step 2: Computer chooses a move
    # -----------------------
    computer = random.choice(valid_moves)
    print(f"Computer chose: {computer}")

    # -----------------------
    # Step 3: Decide who wins
    # -----------------------
    if player == computer:
        ties += 1
        print("It’s a tie!\n")
    elif player == "rock" and computer == "scissors":
        wins += 1
        print("You win! Rock crushes scissors.\n")
    elif player == "scissors" and computer == "paper":
        wins += 1
        print("You win! Scissors cut paper.\n")
    elif player == "paper" and computer == "rock":
        wins += 1
        print("You win! Paper covers rock.\n")
    else:
        losses += 1
        print("You lose!\n")

    # Show score so far
    print(f"Score — Wins: {wins}, Losses: {losses}, Ties: {ties}\n")

    # -----------------------
    # Step 4: Ask to play again
    # -----------------------
    again = input("Play again? (yes/no): ").strip().lower()
    if again not in ("y", "yes"):
        print("Thanks for playing!")
        break

 

This version is straight-line code:

  • No functions to confuse beginners.

  • Just one loop with clear stages: input → computer choice → decision → score → play again.

  • Keeps it accessible, while still reinforcing loops and conditionals.