Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 01 / Stage 1

How Python runs

Goal: Install Python 3.13+, write your first program, and understand what happens when you press "Run". Time: ~1 hour

What you will learn

  • What Python is and where it is used
  • How to install Python 3.13+ on Windows, macOS and Linux
  • How to set up VS Code with the Python extension
  • REPL vs script: two ways to run Python
  • How the interpreter works: source → bytecode → PVM
  • Python versions: why we use 3.13+ only
  • print(), comments and indentation basics

Topics in this part

Practice

Python workbench — write and run code here

Press Run and Python 3.14 loads right in your browser (a one-time download of about 15 MB; after that it works offline). Your code never leaves this page. input() opens a small prompt window.

Try each one yourself first. Then check the solution.


Exercise 1: My intro card

Scenario: On the first day of a coding club, everyone prints a small intro card. What to do: Write a script that prints your name, city and goal on three lines, with a line of - above and below.

Sample output:

------------------------------
Name : Rahul Verma
City : Lucknow
Goal : Become a Python developer
------------------------------

💡 Hint: "-" * 30 makes a line of 30 dashes (* repeats text).


Show the solution to Exercise 1
"""Exercise 1: My intro card.

Run: python ex01.py   (macOS/Linux: python3 ex01.py)
"""

line = "-" * 30

print(line)
print("Name : Rahul Verma")
print("City : Lucknow")
print("Goal : Become a Python developer")
print(line)

Exercise 2: Fix the broken script

Scenario: A friend sent you this code. It does not run.

print "Good morning"
  print("Have a nice day")
# This is a comment
print("Bye)

What to do: Fix all the errors so it prints three lines. Add one comment that explains each fix.

Sample output:

Good morning
Have a nice day
Bye

💡 Hint: Look for Python 2 style, an extra indent, and a missing quote.


Show the solution to Exercise 2
"""Exercise 2: Fix the broken script.

Run: python ex02.py   (macOS/Linux: python3 ex02.py)
"""

print("Good morning")     # Fix 1: print needs brackets in Python 3
print("Have a nice day")  # Fix 2: removed the extra indent
# This is a comment
print("Bye")              # Fix 3: added the missing closing quote

Exercise 3: Date and time with sep and end

Scenario: A railway display shows the date as 26/11/2026 and the time as 16:35. What to do: Using only print() with sep and end (no f-strings yet, they come in Part 2), print:

Sample output:

Date: 26/11/2026 | Time: 16:35

💡 Hint: print("26", "11", "2026", sep="/", end=" | ").


Show the solution to Exercise 3
"""Exercise 3: Date and time with sep and end.

Run: python ex03.py   (macOS/Linux: python3 ex03.py)
"""

print("Date:", end=" ")
print("26", "11", "2026", sep="/", end=" | ")
print("Time:", end=" ")
print("16", "35", sep=":")

Exercise 4: Version checker

Scenario: Your team's project needs Python 3.13+. Write a tiny checker everyone can run. What to do: Print the current Python version. Then print OK if it is 3.13 or newer, else print Please upgrade.

Sample output: (the version line shows whatever Python you have installed)

Your Python: 3.13.1
OK

💡 Hint: import sys and import platform at the top. Use platform.python_version() for the text. To choose between OK and Please upgrade, copy this if/else pattern (you'll learn if in Part 3):

if sys.version_info >= (3, 13):
    print("OK")
else:
    print("Please upgrade")

Show the solution to Exercise 4
"""Exercise 4: Version checker.

Run: python ex04.py   (macOS/Linux: python3 ex04.py)
"""

import platform
import sys

print("Your Python:", platform.python_version())

# if/else picks one of two lines to run (you will learn it in Part 3)
if sys.version_info >= (3, 13):
    print("OK")
else:
    print("Please upgrade")

Exercise 5: Tea stall receipt banner

Scenario: "Chai Point, Bengaluru" wants a neat receipt header 32 characters wide. What to do: Print a banner with a border of *, the shop name centred, and a tagline centred.

Sample output:

********************************
*          Chai Point          *
*    Fresh chai since 1998     *
********************************

💡 Hint: "Chai Point".center(30) (a string method, Part 2) puts the text in the middle of a 30-wide string. Join pieces with +: "*" + ... + "*".


Show the solution to Exercise 5
"""Exercise 5: Tea stall receipt banner.

Run: python ex05.py   (macOS/Linux: python3 ex05.py)
"""

width = 32
inner = width - 2  # space between the two * borders

print("*" * width)
print("*" + "Chai Point".center(inner) + "*")
print("*" + "Fresh chai since 1998".center(inner) + "*")
print("*" * width)

Exercise 6: Bytecode detective

Scenario: You want to see how many bytecode steps Python needs for a simple GST calculation. What to do: Copy the def pattern from the README (functions are taught in Part 5) to write add_gst(price) that returns price * 1.18. Use the dis module to print its bytecode, and then print how many instructions it has. Also print where a billing.py module's bytecode would be cached, and print add_gst(100) as a check.

Sample output: (the bytecode listing and names may differ by version)

  ... bytecode listing ...
Number of instructions: 5
Cache file: __pycache__/billing.cpython-313.pyc
Check: add_gst(100) = 118.0

💡 Hint: dis.get_instructions(add_gst) gives the instructions one by one; len(list(...)) counts them. Use importlib.util.cache_from_source("billing.py"). Print round(add_gst(100), 2) so a tiny float error does not show.

Show the solution to Exercise 6
"""Exercise 6: Bytecode detective.

Run: python ex06.py   (macOS/Linux: python3 ex06.py)
"""

import dis
import importlib.util


def add_gst(price):
    """Return the price with 18% GST added."""
    return price * 1.18


dis.dis(add_gst)

# get_instructions() gives the steps one by one; list() collects them (Part 4)
instructions = list(dis.get_instructions(add_gst))
print("Number of instructions:", len(instructions))
print("Cache file:", importlib.util.cache_from_source("billing.py"))
# round() hides tiny float errors like 118.00000000000001 (Part 2)
print("Check: add_gst(100) =", round(add_gst(100), 2))

Common mistakes

Mistake Why it is wrong Fix
'python' is not recognized Python is not on PATH Re-install with "Add to PATH" ticked, or use py / python3
print "Hello" Python 2 style; print is a function in Python 3 print("Hello")
Mixing tabs and spaces Gives TabError / IndentationError Use 4 spaces (VS Code does this for you)
Indenting a line for no reason IndentationError: unexpected indent Only indent inside blocks like if, for, def
Typing python hello.py inside the REPL (>>>) That is a terminal command, not Python code exit() first, then run it in the terminal
Saving the file as hello.py.txt Python cannot find hello.py Turn on file extensions and rename to .py
Naming your file random.py or dis.py It hides the real stdlib module on import Use unique names like my_random.py

Quick recap

  • Python is a readable, general-purpose language used in web, data, AI and automation.
  • Install 3.13+ from python.org and check with python --version.
  • VS Code + Python extension = edit, run and debug in one place.
  • REPL is for quick tests; .py scripts are for real programs.
  • Python compiles source to bytecode, caches it in __pycache__/*.pyc, and the PVM runs it.
  • print() shows output; sep and end change how it looks.
  • # starts a comment. Indentation (4 spaces) is part of the code.

Checklist

  • I installed Python 3.13+ and python --version works.
  • I set up VS Code with the Python extension.
  • I can use the REPL and exit it.
  • I can write and run a .py script.
  • I can explain source → bytecode → PVM in my own words.
  • I know what __pycache__ and .pyc files are.
  • I can use print() with sep and end, and write comments.
  • I indent blocks with 4 spaces.

Search the guide