AHS CODING CLUB

Welcome to AHS Code Club

This page will serve as a go to page for lesson, activites and code

Get in Touch
Back to Home Page

Can you Tell What the Following Program Does?

It uses Almost All of the Topics We Studies in Python Including:

import random  # This is the module we'll use

def get_random_number():
    """Generates a random number between 1 and 10."""
    return random.randint(1, 10)

def get_user_guess():
    """Prompts the user for a guess and returns it as an integer."""
    guess = input("Enter your guess (1-10): ")
    return int(guess)

def play_game():
    """Main game logic."""
    number_to_guess = get_random_number()
    guess = None
    attempts = 0
    guesses = []

    print("Welcome to the Guess the Number Game!")
    print("Try to guess the number between 1 and 10.")

    while guess != number_to_guess:
        guess = get_user_guess()
        guesses.append(guess)
        attempts += 1

        if guess < number_to_guess:
            print("Too low!")
        elif guess > number_to_guess:
            print("Too high!")
        else:
            print(f"Correct! The number was {number_to_guess}.")
            print(f"It took you {attempts} attempts.")

    print("\nYour guesses were:")
    for g in guesses:
        print(g)

# Run the game
play_game()
    

Pseudocode and Algorithms

Aglorithms

What is an Algorithm?
An algorithm is a step-by-step set of instructions for solving a problem or completing a task.

An algorithm is a recipe for solving a problem.

How would you find the largest number given a list of numbers?

def find_max(num_list):
    max_num = num_list[0]
    for num in num_list:
        if num > max_num:
            max_num = num
    return max_num    

Pseudocode

What is Pseudocode
Pseudocode is a way to describe an algorithm using plain, structured language that looks like code — but isn't meant to run on a computer.

Key Points About Pseudocode

Pseudocode to find Max Number

START
SET max TO first number in the list
FOR each number in the list
    IF number > max THEN
        SET max TO number
    ENDIF
ENDFOR
PRINT max
END

Pseudocode Rules

There is no strict standard, but it is usually

Submit Code Here