Practice Exercises on One Coding Concept with Self-Check Output and Hidden Solutions

Get five practice exercises on one programming concept, graded from easy to hard, each with exact expected output to check yourself and solutions placed at the end.

Prompt

Prompt
You are a patient programming tutor who writes practice sets for self-taught learners.

Before writing anything, ask me these questions in one numbered message, then wait for my answers:
1. Which programming language are you learning?
2. Which single concept do you want to practice (for example loops, recursion, string slicing)?
3. What is your level: total beginner, can write small scripts, or comfortable with functions and classes?
4. Is there anything you have not learned yet that I should avoid?

Then write five exercises on that one concept, in rising difficulty.

Rules:
- Exercise 1 needs only the concept itself. Exercise 5 combines it with one other basic skill I already know.
- Each exercise gives a fixed sample input and the exact expected output, so I can check my code by running it.
- Use only features I said I know. No external libraries.
- Keep each task under 80 words.
- Put all solutions after a line reading "SOLUTIONS BELOW: try first". Give each solution a 1-2 sentence explanation of the key idea.

Output format:
## Exercise 1 to 5: title, difficulty (1-5), task, sample input, expected output, one-line hint
## Solutions: numbered code blocks, each with a short explanation
## Common Mistakes: 3 bullets

End with one line naming any assumption you made about my level or any feature you avoided.

Example output

At a glanceFive for-loop exercises, easy to hardEach exercise lists exact expected output; solutions come at the end
  1. Countdown1/5Print 5 down to 1 with range()
  2. Sum a List2/5Add up numbers without sum()
  3. Long Words3/5Count words with more than 4 letters
  4. Largest Number4/5Find the largest without max()
  5. Pass or Fail Report5/5Print Pass if 60 or above, else Fail

Example for: a beginner learning Python for loops who knows variables, print, lists and if statements.

Exercise 1: Countdown

Difficulty: 1/5
Task: Use a for loop and range() to print the numbers 5 down to 1, one per line.
Sample input: none
Expected output:

5
4
3
2
1

Hint: range() can take a negative step.

Exercise 2: Sum a List

Difficulty: 2/5
Task: Add up every number in the list with a loop. Do not use sum().
Sample input: nums = [4, 7, 1, 8]
Expected output: 20
Hint: Start a total at 0 before the loop.

Exercise 3: Long Words

Difficulty: 3/5
Task: Count how many words have more than 4 letters.
Sample input: words = ["cat", "python", "loop", "banana", "if"]
Expected output: 2
Hint: len() gives a word's length.

Exercise 4: Largest Number

Difficulty: 4/5
Task: Find the largest number without using max().
Sample input: nums = [12, 45, 7, 45, 30]
Expected output: 45
Hint: Assume the first item is the largest, then compare.

Exercise 5: Pass or Fail Report

Difficulty: 5/5
Task: For each score, print the score followed by Pass if it is 60 or above, otherwise Fail.
Sample input: scores = [72, 95, 58, 88]
Expected output:

72 Pass
95 Pass
58 Fail
88 Pass

Hint: Put an if/else inside the loop.


SOLUTIONS BELOW: try first

Solutions

1.

for n in range(5, 0, -1):
    print(n)

range stops before 0, and the step of -1 makes it count down.

2.

total = 0
for n in nums:
    total = total + n
print(total)

The loop adds each item to a running total.

3.

count = 0
for w in words:
    if len(w) > 4:
        count += 1
print(count)

Only words that pass the length check increase the counter.

4.

biggest = nums[0]
for n in nums:
    if n > biggest:
        biggest = n
print(biggest)

You keep the best value seen so far and replace it when a larger one appears.

5.

for s in scores:
    if s >= 60:
        print(s, "Pass")
    else:
        print(s, "Fail")

The loop visits each score, and the if/else decides which word to print.

Common Mistakes

  • Writing range(5, 1, -1), which stops at 2 because the end value is excluded.
  • Setting total = 0 inside the loop, which resets it on every pass.
  • Using > instead of >= in Exercise 5, which marks a score of exactly 60 as Fail.

Assumption: you have not learned functions yet, so every exercise is a short script with no def.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Asking language, concept and level first keeps the exercises at your level instead of generic ones.
  • Exact expected output for each task lets you check your code by running it, with no need to peek at answers.
  • Placing solutions after a clear stop line, with short explanations, helps you try first and then learn from the fix.

Use this in ChatGPT, Claude or Gemini after a lesson or tutorial, when you want practice on one concept. Know your language and the concept you want to drill. Scroll slowly so you don't see the solutions too early.

Common edits

  • Ask for ten exercises, or a set on two related concepts such as loops and lists.
  • Ask for test cases or edge-case inputs in place of a single sample input.

Prompt details

By
Prompts-GPT editors
Published

Did this prompt work?

Keep exploring

More in Coding