Practice core concepts with exercises on prime numbers, functions, and loops, plus a threading introduction.
Variables, Conditionals, and Loops: Practical Exercises

Practice is the fastest way to internalize fundamentals. This exercise combines functions, loops, and conditionals around a classic challenge: finding prime numbers in a range.

Running the script

Save code into primes.py and execute it from terminal.

Prime-check function

A dedicated function checks if a number is prime by testing divisibility.

Range iteration

Use range(start, end + 1) to process candidates and count results.

Performance timing

Use timeit to measure execution time and compare approaches.

Threading approach

Split ranges and process them in separate threads to practice basic concurrency.

def is_prime(num):
    if num == 1:
        return False
    for i in range(2, num):
        if num % i == 0:
            return False
    return True