Tutorials Logic, IN info@tutorialslogic.com

Python Exercises: Beginner Practice with Guided Solutions

Exercise Path

Exercises turn reading into skill. A good exercise asks you to recall the idea, change it, and explain why the result works.

Use this page after reading a lesson or when you need a quick check before moving to the next topic.

Do not copy the solution first. Write a small attempt, run it, read the error, and then compare with the guided answer.

Beginner Exercises

Start with variables, input, output, and conversion. These exercises train the habit of checking value types early.

  • Ask for a name and print a greeting.
  • Ask for two numbers and print their sum.
  • Convert minutes into hours and minutes.
  • Build a bill total with tax.

Sum Two Numbers

Sum Two Numbers
first = int(input("First number: "))
second = int(input("Second number: "))

print(first + second)

input() returns text, so int() converts each value before addition.

Data Exercises

Practice lists, dictionaries, sets, and strings by transforming small data collections.

  • Remove duplicate names from a list.
  • Count how many times each word appears.
  • Create a dictionary from two lists.
  • Clean a comma-separated tag string.

Word Counter

Word Counter
sentence = "python makes python practice simple"
counts = {}

for word in sentence.split():
    counts[word] = counts.get(word, 0) + 1

print(counts)
Output
{'python': 2, 'makes': 1, 'practice': 1, 'simple': 1}

The dictionary stores each word as a key and updates its count each time the word appears.

Function Exercises

Function exercises train reusable behavior and clean return values.

  • Write a function that checks even numbers.
  • Write a function that returns the largest value in a list.
  • Write a function that formats a user profile.
  • Write a function that validates a password length.

Debug Exercises

Debugging practice is part of learning Python, not a separate skill to postpone.

  • Fix one TypeError from adding text and numbers.
  • Fix one KeyError from a missing dictionary key.
  • Fix one IndexError from an empty list.
  • Fix one FileNotFoundError from a wrong path.
Skill check

Can You Practice Alone?

5 checks
  • Attempt the exercise before reading the solution.
  • Run code after each small change.
  • Explain the input, process, and output in one sentence.
  • Fix the first error before changing the whole program.
  • Turn one exercise into a small project when the idea feels clear.

Exercise Decisions

0 of 2 checked

Q1. What is the best order when using an exercise page?

Q2. What should you do after solving the direct version?

Exercise Habits to Avoid

  • Reading the solution first

    Write one attempt, even if incomplete, before comparing with the answer.
  • Only solving easy direct copies

    Change the input shape or add one edge case after the first solution works.
  • Skipping error messages

    Read the exception type and line number before asking for help.

Try this next

Exercise Progression

0 of 3 completed

  1. Solve the exact exercise after reading the lesson.
  2. Change the data type, input source, or output format.
  3. Break the code on purpose and explain the traceback.

Questions About Exercise

Do at least three: one direct example, one small variation, and one debugging exercise.

No. Memorize the pattern: input, process, output, and how the data changes.

Reduce it to a smaller step, print intermediate values, and compare your code with the closest tutorial example.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.