Learning to code isn’t just about reading tutorials—it’s about rolling up your sleeves and practicing. In this post, we’ll go through 20 simple exercises that are perfect for beginners. Each one comes with examples and Python solutions so you can try them out right away.

1. Print “Hello, World!”

What the exercise wants: Write the simplest possible program that outputs a message on the screen. This shows how to run code and get visible results.

What you’ll use: print() function — no input, just output.

Sample Output

Hello, World!

Python Solution

print("Hello, World!")

2. Simple Calculator

What the exercise wants: Take two numbers from the user and calculate their sum, difference, product, and quotient. This teaches you input handling and basic arithmetic.

What you’ll use: input() to get numbers, float() to convert them, arithmetic operators (+ - * /), and print() for results.

Sample Input

8
2

Sample Output

Addition: 10.0
Subtraction: 6.0
Multiplication: 16.0
Division: 4.0

Python Solution

a = float(input("Enter first number: ").strip())
b = float(input("Enter second number: ").strip())

print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b if b != 0 else "Infinity")

3. Odd or Even Checker

What the exercise wants: Decide whether an integer is odd or even.

What you’ll use: modulo %, conditional expression

Sample Input

7 is odd

Sample Output

7 is odd

Python

n = int(input().strip())
print(f"{n} is {'even' if n % 2 == 0 else 'odd'}")

4. Number Guessing Game

What the exercise wants: Computer picks a random number; user keeps guessing until correct, with high/low hints.

What you’ll use: random.randint(), while loop, if/elif/else.

Sample Run

Guess (1-10): 5
Too low
Guess (1-10): 8
Correct!

Python Solution

import random
secret = random.randint(1, 10)
while True:
    g = int(input("Guess (1-10): ") or 0)
    if g < secret:
        print("Too low")
    elif g > secret:
        print("Too high")
    else:
        print("Correct!")
        break

5. Multiplication Table

What the exercise wants: Print the 1–10 multiplication table for a given number.

What you’ll use: for loop, f-strings.

Sample Input

3

Sample Output

3 x 1 = 3
...
3 x 10 = 30

Python Solution

n = int(input().strip())
for i in range(1, 11):
    print(f"{n} x {i} = {n*i}")

6. Palindrome Checker

What the exercise wants: Check if text reads the same forwards and backwards (ignore case and spaces/punctuation).

What you’ll use: string cleanup, .lower(), slicing [::-1].

Sample Input

RaceCar

Sample Output

RaceCar is a palindrome

Python Solution

s = input().strip()
clean = ''.join(ch.lower() for ch in s if ch.isalnum())
print(f"{s} is {'a palindrome' if clean == clean[::-1] else 'not a palindrome'}")

7. Fibonacci Sequence

What the exercise wants: Print the first n Fibonacci numbers.

What you’ll use: variables to track last two values, for loop, list join.

Sample Input

6

Sample Output

0 1 1 2 3 5

Python Solution

n = int(input().strip())
a, b = 0, 1
seq = []
for _ in range(n):
    seq.append(str(a))
    a, b = b, a + b
print(' '.join(seq))

8. Factorial Calculator

What the exercise wants: Compute n! (product of 1..n).

What you’ll use: for loop multiplication (or recursion).

Sample Input

5

Sample Output

120

Python Solution

n = int(input().strip())
f = 1
for i in range(2, n+1):
    f *= i
print(f)

9. Word Counter

What the exercise wants: Count how many words are in a sentence.

What you’ll use: str.split(), len().

Sample Input

I love programming

Sample Output

3

Python Solution

s = input().strip()
print(len(s.split()))

10. To-Do List (Mini CLI)

What the exercise wants: Add, view, and remove tasks in a simple looped menu.

What you’ll use: lists, while loop, if/elif/else.

Sample Run

1
Finish homework
2
1 Finish homework

Python Solution

tasks = []
while True:
    print("1) Add  2) View  3) Remove  4) Exit")
    c = input("> ").strip()
    if c == "1":
        tasks.append(input("Task: ").strip()); print("Added.")
    elif c == "2":
        if tasks:
            for i, t in enumerate(tasks, 1):
                print(i, t)
        else:
            print("No tasks.")
    elif c == "3":
        i = int(input("Index: ") or 0)
        if 1 <= i <= len(tasks):
            tasks.pop(i-1); print("Removed.")
        else:
            print("Invalid index.")
    elif c == "4":
        break
    else:
        print("Try 1-4.")

11. Reverse a String

What the exercise wants: Output the reversed version of the input text.

What you’ll use: slicing [::-1].

Sample Input

hello

Sample Output

olleh

Python Solution

print(input().strip()[::-1])

12. Largest of Three Numbers

What the exercise wants: Read three numbers and print the largest.

What you’ll use: input().split(), map(), max().

Sample Input

4 9 2

Sample Output

9

Python Solution

a, b, c = map(float, input().split())
print(max(a, b, c))

13. Temperature Converter (C ↔ F)

What the exercise wants: Convert Celsius to Fahrenheit or vice versa based on a scale prefix.

What you’ll use: conditionals, arithmetic.

Sample Input

C 25

Sample Output

77.0

Python Solution

scale, val = input().split()
x = float(val)
print(x * 9/5 + 32 if scale.upper() == 'C' else (x - 32) * 5/9)

14. Simple Interest

What the exercise wants: Compute simple interest using P, R, T.

What you’ll use: map(float, ...), arithmetic formula P*R*T/100.

Sample Input

1000 5 2

Sample Output

100.0

Python Solution

P, R, T = map(float, input().split())
print(P * R * T / 100)

15. Prime Number Checker

What the exercise wants: Tell whether n is prime.

What you’ll use: loop up to √n, early break on divisor.

Sample Input

13

Sample Output

prime

Python Solution

n = int(input().strip())
if n < 2:
    print("not prime")
else:
    i, ok = 2, True
    while i*i <= n:
        if n % i == 0:
            ok = False; break
        i += 1
    print("prime" if ok else "not prime")

16. Sum of Digits

What the exercise wants: Add up all digit characters in the input.

What you’ll use: generator expression over string, sum().

Sample Input

1234

Sample Output

10

Python Solution

s = input().strip()
print(sum(int(ch) for ch in s if ch.isdigit()))

17. Count Vowels

What the exercise wants: Count how many vowels are in the input text.

What you’ll use: .lower(), membership checks with a set.

Sample Input

programming

Sample Output

3

Python Solution

s = input().lower()
vowels = set('aeiou')
print(sum(ch in vowels for ch in s))

18. Rock–Paper–Scissors

What the exercise wants: Play one round vs. computer and report win/lose/tie.

What you’ll use: random.choice(), tuple-based win rules, if/elif.

Sample Run

rock
Computer chose: scissors
You win!

Python Solution

import random
user = input("rock/paper/scissors: ").strip().lower()
cpu = random.choice(["rock", "paper", "scissors"])
print("Computer chose:", cpu)
if user == cpu:
    print("Tie!")
elif (user, cpu) in {("rock","scissors"), ("paper","rock"), ("scissors","paper")}:
    print("You win!")
else:
    print("You lose!")

19. Min & Max in a List

What the exercise wants: Read numbers on one line and print the minimum and maximum.

What you’ll use: split(), map(float), min(), max().

Sample Input

5 9 1 7 3

Sample Output

1 9

Python Solution

nums = list(map(float, input().split()))
print(min(nums), max(nums))

20. Basic Password Validator

What the exercise wants: Validate a password: length ≥ 8, has at least one letter and one digit.

What you’ll use: len(), any(), .isalpha(), .isdigit(), boolean logic.

Sample Input

Hello123

Sample Output

valid

Python Solution

pw = input().strip()
ok = (len(pw) >= 8 and any(ch.isalpha() for ch in pw) and any(ch.isdigit() for ch in pw))
print("valid" if ok else "invalid")