Python Course — Day 3

Variables, Types & Debugging

Today you'll set up your coding workspace in VS Code, learn how Python stores and uses data, and — most importantly — learn how to read errors and fix your code when things go wrong.

Lab Modules

Meet Visual Studio Code

Last time we wrote code in Notepad. That works, but it's like writing an essay with a crayon — possible, but there are better tools. Today we'll use Visual Studio Code (VS Code), the tool most professional programmers use.

💡 What Is VS Code?

VS Code is a code editor — like Notepad, but built specifically for programmers. It looks like Notepad (you type text, you save files), but it has special features that make coding much easier. The biggest one is syntax highlighting — it colors different parts of your code so you can read it more easily. Keywords in one color, text in another, numbers in a third. This coloring is purely for your eyes — the computer doesn't care about colors, but it makes a huge difference for humans reading the code.

🏠 Real-World Analogy

Notepad is like a plain notebook — you can write anything, but there's no help. VS Code is like a smart notebook that highlights important words, tells you when you misspell something, and has colored tabs to organize your pages. The writing is the same — but the experience is much better.

💡 Extensions — Adding Superpowers

One of the best things about VS Code is extensions. An extension is like an app for your phone. Your phone can make calls by default, but you install apps to add more features (camera filters, games, maps). Similarly, VS Code can edit text by default, but you install extensions to add more features — like special support for Python, or for other programming languages. By itself, VS Code doesn't have special support for any particular programming language. You add that support by installing the right extension.

TASK 1.1 Open VS Code
  1. Press the Windows key, type Visual Studio Code (or just code), and click on it.
  2. VS Code will open. You'll see a Welcome tab. Take a moment to look around — don't click anything yet, just observe.
  3. Notice the left sidebar — it has icons for files, search, source control, and more.
  4. Notice the top menu bar — File, Edit, View, etc. — similar to other apps you've used.
TASK 1.2 Explore the Interface
  1. Look at the left sidebar. The very first icon at the top looks like two overlapping documents — this is the Explorer panel. Click it. This is where you'll see your files and folders.
  2. The icon that looks like a magnifying glass is Search — you can search across all your files.
  3. Now look at the bottom bar (the blue or colored bar at the very bottom of the window). It shows useful information — we'll use this later.
  4. Click File → New File (or press Ctrl + N). A blank tab appears — just like a new document in Notepad. Type Hello from VS Code! in it. You can close this without saving (click the X on the tab, click "Don't Save").
TASK 1.3 Install the Python Extension

Let's add Python support to VS Code by installing an extension.

  1. Look at the left sidebar. Click the icon that looks like 4 small squares (one square is slightly detached) — this is the Extensions panel.
  2. In the search box at the top, type Python.
  3. The very first result should be "Python" by Microsoft. It will have millions of downloads. Click the blue Install button next to it.
  4. Wait a few seconds. Once installed, the button will change to "Uninstall" (which means it's now installed). That's it!

You just installed an extension! This adds Python-specific features: syntax highlighting (coloring Python code), error detection, and more. The Python extension doesn't change what your code does — it just makes it easier for you to read and write Python.

TASK 1.4 See Syntax Highlighting in Action
  1. Press Ctrl + N to create a new file.
  2. Now click on "Select a language" shown in the editor area (or click "Plain Text" in the bottom-right corner of the VS Code window). Type Python and select it. This tells VS Code to treat this file as Python.
  3. Now type this code:
PYTHONtest
name = "Pooja" age = 20 print("Hello,", name, "you are", age)
  1. Look at the colors! "Pooja" and "Hello," are in one color (they're text strings). 20 is in a different color (it's a number). print is in yet another color (it's a built-in function). This is syntax highlighting.
  2. You can close this file without saving — it was just for testing.
📝 Quiz

What does syntax highlighting do?

A Makes the code run faster
B Fixes errors automatically
C Colors different parts of code so humans can read it more easily
D Translates Python to English
Correct! Syntax highlighting is purely visual — it colors keywords, strings, numbers, etc. in different colors so you can read the code more easily. Python itself doesn't care about colors at all.
📝 Quiz

What is a VS Code extension?

A A file type like .py or .txt
B An add-on that gives VS Code extra features, like phone apps
C A programming language
D A keyboard shortcut
Correct! Extensions add extra features to VS Code, just like installing apps adds features to your phone. The Python extension adds Python-specific features like syntax highlighting and error detection.

Setting Up Your Workspace

Let's create our Day 3 project folder in VS Code and learn to manage files, folders, and the integrated terminal — all from one window.

TASK 2.1 Open Your Course Folder in VS Code
  1. In VS Code, click File → Open Folder...
  2. Navigate to H:\Pooja and click Select Folder.
  3. VS Code may ask "Do you trust the authors?" — click Yes, I trust the authors.
  4. Now look at the Explorer panel (left sidebar, first icon). You should see the Pooja folder and inside it, the day2 folder with all the files you made last time.
TASK 2.2 Create the Day3 Folder and Files
  1. In the Explorer panel, hover your mouse over POOJA (the folder name at the top). You'll see four small icons appear. The one that looks like a folder with a plus sign creates a new folder. Click it.
  2. Type day3 and press Enter. You just created a new folder!
  3. Now click on the day3 folder to select it. Then click the icon that looks like a file with a plus sign (next to the folder icon).
  4. Type test.py and press Enter. A new empty file opens in the editor. The .py extension tells VS Code this is a Python file, so syntax highlighting will work automatically.
TASK 2.3 Rename and Delete — Managing Files
  1. Create another file inside day3: click the new-file icon, name it delete_me.py.
  2. To rename it: right-click on delete_me.py in the Explorer → click Rename → change the name to temporary.py → press Enter.
  3. To delete it: right-click on temporary.py → click Delete → confirm. The file is gone.
  4. You can also create folders this way: right-click on day3 → New Folder → name it practice. Then right-click on practice → Delete to remove it.

Everything you do in VS Code's Explorer panel is real — the files and folders exist on your H: drive. You can verify by opening File Explorer and navigating to H:\Pooja\day3.

TASK 2.4 Open the Integrated Terminal
  1. Press Ctrl + ` (the backtick key — it's usually above the Tab key, below Esc). A terminal panel will appear at the bottom of VS Code.
  2. Alternatively, click View → Terminal from the top menu.

💡 This Is the Same Terminal!

This terminal is exactly the same as the PowerShell window you opened separately in Day 2. All the commands work the same way — pwd, ls, cd, python, etc. The only difference is that it's built into VS Code, so you don't have to switch between two separate windows. You write code in the top half and run it in the bottom half. Very convenient!

  1. Try a command in the terminal: type pwd and press Enter. It should show H:\Pooja (or wherever your folder is).
  2. Navigate into your day3 folder: cd day3
  3. Type ls to see your files. You should see test.py.
TASK 2.5 Different Shell Types

Look at the top-right area of the terminal panel. You'll see a dropdown or text that says "powershell" (or similar). Click the small dropdown arrow (˅) next to it.

  1. You'll see options like: PowerShell, Command Prompt, Git Bash (if installed). These are different shells — different "languages" for talking to your computer.
  2. Select Command Prompt. A new terminal tab opens. Type dir and press Enter. It shows files — just like ls in PowerShell.
  3. Switch back to PowerShell by clicking its tab, or open a new one with the dropdown.

💡 Different Shells, Same Idea

There are different types of terminals (shells): PowerShell and Command Prompt on Windows, Bash and Zsh on Mac/Linux. They all do the same job (let you type commands), but the commands are slightly different. For example, to list files: ls (PowerShell/Mac/Linux), dir (Command Prompt). Once you learn one, learning others is easy — the concepts are identical, only the command names change. We'll use PowerShell for this course.

📝 Quiz

What is the VS Code integrated terminal?

A A completely different terminal that only works inside VS Code
B A place where VS Code shows error messages only
C A feature that automatically runs your Python code
D The same system terminal (PowerShell), but built into VS Code for convenience
Correct! The integrated terminal is identical to opening PowerShell separately. It uses the same shell, same commands, same PATH. The only advantage is convenience — you can see your code and terminal in one window.

Running Python Inside VS Code

Let's make sure everything works end-to-end: write Python code in VS Code, run it in the terminal, see the output — all in one window.

TASK 3.1 Write and Run Your First File in VS Code
  1. Click on test.py in the Explorer panel (the file you created in Module 2). It opens in the editor.
  2. Type this code:
PYTHONtest.py
print("Hello from VS Code!") print("Python is working perfectly.") print(10 + 20)
  1. Save the file: press Ctrl + S. (Notice the dot on the tab disappears — that dot means "unsaved changes".)
  2. Click on the terminal panel at the bottom. Make sure you're in the day3 folder. If not, type cd H:\Pooja\day3.
  3. Run it: type python test.py and press Enter.
Output
PS H:\Pooja\day3> python test.py Hello from VS Code! Python is working perfectly. 30

This is now your workflow: write code in the editor (top) → save → run in the terminal (bottom) → see output. This is how professional programmers work every day.

⚠️ Always Save Before Running!

When you run python test.py, Python reads the file from disk. If you changed code in the editor but didn't press Ctrl + S, Python will run the old saved version, not what you see on screen. Always save first! Look for the dot (●) on the tab — if it's there, you have unsaved changes.


Variables & Data Types

This is the foundation of everything in programming. A variable is how your program remembers things.

🏠 Real-World Analogy

Imagine you have labeled boxes on a shelf. One box is labeled age and inside it you put a slip of paper that says 20. Another box is labeled name and inside it is "Pooja". You can look inside any box to see what's there, change what's inside, or use the contents to do something. That's exactly what a variable is — a named box that stores a value.

💡 Creating a Variable (Assignment)

To create a variable, you write: name = "Pooja". This is called assignment. The = sign does NOT mean "equals" like in math. It means: "take the value on the right side and store it in the box named on the left side." Think of = as an arrow pointing left: name ← "Pooja".

TASK 4.1 Create Your First Variables

Create a new file: in the Explorer, right-click day3 → New File → name it variables.py. Type this code:

PYTHONvariables.py
# Creating variables — storing values in named boxes name = "Pooja" age = 20 height = 5.4 # Printing the values stored inside each variable print(name) print(age) print(height)
  1. Type the code above (don't copy-paste — typing helps you learn). Save with Ctrl + S.
  2. Run it in the terminal: python variables.py
Output
PS H:\Pooja\day3> python variables.py Pooja 20 5.4

Notice: print(name) doesn't print the word "name" — it prints what's inside the variable name, which is "Pooja". The variable is the box, print opens the box and shows the contents.

💡 The Three Basic Data Types

int (integer) — Whole numbers with no decimal point: 10, -3, 0, 2026
float (floating-point) — Numbers with a decimal point: 5.4, 3.14, -0.5, 100.0
str (string) — Text, always wrapped in quotes: "Hello", "Pooja", "123" (yes, "123" in quotes is text, NOT a number!)
TASK 4.2 Updating Variables

Create update.py and type this:

PYTHONupdate.py
# A variable can be changed (updated) at any time score = 0 print("Starting score:", score) score = 10 print("After level 1:", score) score = 25 print("After level 2:", score) score = score + 5 print("Bonus points! :", score)
  1. Type it, save, and run: python update.py
  2. Look at the last line carefully: score = score + 5. This means: "take the current value of score (25), add 5 to it, and store the result (30) back into score." The right side is calculated first, then stored into the left side.
Output
Starting score: 0 After level 1: 10 After level 2: 25 Bonus points! : 30
TASK 4.3 Computing with Variables & Operators

Create operators.py:

PYTHONoperators.py
a = 15 b = 4 print("a + b =", a + b) # Addition print("a - b =", a - b) # Subtraction print("a * b =", a * b) # Multiplication print("a / b =", a / b) # Division (always gives a float) # Store the result in a new variable total = a + b print("total =", total)
Output
a + b = 19 a - b = 11 a * b = 60 a / b = 3.75 total = 19
TASK 4.4 Assigning One Variable to Another

Create copy_var.py:

PYTHONcopy_var.py
original = 100 copy = original # copy gets the VALUE that is inside original (100) print("original:", original) print("copy :", copy) # Now change original original = 999 print("--- after changing original ---") print("original:", original) print("copy :", copy) # copy still has 100!
  1. Type, save, run. What is copy after we change original?
  2. Key insight: copy = original copies the value at that moment. After that, they're independent. Changing original later doesn't change copy.
TASK 4.5 String Concatenation — Joining Text

Create strings.py:

PYTHONstrings.py
first_name = "Pooja" last_name = "Sharma" # The + operator JOINS strings together (concatenation) full_name = first_name + " " + last_name print(full_name) # The * operator REPEATS a string line = "=-" * 20 print(line) greeting = "Hello, " + full_name + "!" print(greeting)
Output
Pooja Sharma =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Hello, Pooja Sharma!

Important: the + operator does different things depending on the data type. With numbers, it adds. With strings, it joins (concatenates). 5 + 3 gives 8. "5" + "3" gives "53".

📝 Quiz

What does x = x + 3 mean?

A x is equal to x plus 3 (a math equation)
B Take current value of x, add 3, store the result back into x
C Create a new variable called x + 3
D This is an error in Python
Correct! The right side (x + 3) is calculated first using x's current value. Then the result is stored back into x. If x was 10, after this line x becomes 13.
📝 Quiz — Predict the Output

What does print("5" + "3") output?

A 8
B "8"
C 53
D Error
Correct! "5" and "3" are strings (they have quotes), not numbers. The + operator joins strings together: "5" + "3""53".
✏️ Complete the Code

Fill in the blanks so this code prints My age is 20:

PYTHONfill in
age = ??? print("My age is", ???)
Line 1: age = 20 — Store the number 20 in the variable age.
Line 2: print("My age is", age) — Print the text followed by the value inside age.
✏️ Complete the Code

Fill in the blanks so that result contains 15:

PYTHONfill in
x = 10 y = 5 result = ??? print(result)
result = x + y — Python calculates 10 + 5 and stores 15 into result.

Reading Errors — The Art of Debugging

This is the most important skill you'll learn today. Errors happen to every programmer — beginners and experts with 20 years of experience. The difference is knowing how to read the error message and find the problem. Python actually tells you exactly what went wrong and on which line — you just need to know where to look.

💡 What Is Debugging?

Debugging means finding and fixing errors (called "bugs") in your code. The word comes from the early days of computing when an actual moth got stuck inside a computer and caused problems. Every single programmer in the world writes code with bugs. It's not a sign of being bad — it's a normal part of writing code. What matters is learning to fix them.

💡 How to Read a Python Error (Traceback)

When Python finds an error, it shows you a message called a traceback. It has 3 key pieces of information:

1. Which file — the name of the file with the problem
2. Which line number — the exact line where Python got confused
3. What kind of error — what went wrong (the last line of the traceback)

TASK 5.1 Create a Bug on Purpose — NameError

Create bug1.py with this intentionally broken code:

PYTHONbug1.py
1 message = "Hello World" 2 print(mesage)

Save and run: python bug1.py

Traceback (most recent call last): File "H:\Pooja\day3\bug1.py", line 2, in <module> print(mesage) ^^^^^^^ NameError: name 'mesage' is not defined. Did you mean: 'message'?

📖 How to Read This Traceback

Step 1 — Find the file: File "H:\Pooja\day3\bug1.py" — it's in bug1.py
Step 2 — Find the line number: line 2 — the problem is on line 2
Step 3 — Read the actual line: print(mesage) — this is what Python tried to run
Step 4 — Read the error type: NameError: name 'mesage' is not defined — Python doesn't know any variable called mesage
Step 5 — Python even suggests: Did you mean: 'message'? — we misspelled "message"!
  1. Look at VS Code — click on line 2. See the typo? mesage instead of message (missing an 's').
  2. Fix it: change mesage to message on line 2. Save and run again. It works!
TASK 5.2 SyntaxError — Missing Quotes

Create bug2.py:

PYTHONbug2.py
1 city = "Mumbai" 2 country = "India 3 print(city, country)
File "H:\Pooja\day3\bug2.py", line 2 country = "India ^ SyntaxError: EOL while scanning string literal
  1. Read the traceback: Line 2, SyntaxError — "EOL while scanning string literal" means Python was reading a string (text in quotes) but reached the End Of Line (EOL) without finding the closing quote.
  2. Fix: Add the missing closing quote on line 2: country = "India"
TASK 5.3 TypeError — Mixing Types

Create bug3.py:

PYTHONbug3.py
1 age = 20 2 message = "I am " + age + " years old" 3 print(message)
Traceback (most recent call last): File "H:\Pooja\day3\bug3.py", line 2, in <module> message = "I am " + age + " years old" ~~~~~~~~^~~~~ TypeError: can only concatenate str (not "int") to str
  1. Line 2, TypeError — Python can't join a string ("I am ") and an integer (age which is 20) with +. You can only + strings with other strings.
  2. Fix: Convert the number to a string: message = "I am " + str(age) + " years old". The str() function converts a number into text.
TASK 5.4 Find the Bug from the Traceback

Create bug4.py with this code. There's a bug. Don't try to spot the bug by reading the code — run it first and use the traceback to find it.

PYTHONbug4.py
1 price = 50 2 quantity = 3 3 total = price * quantity 4 print("Total cost:" total)
  1. Save and run it. Read the error message.
  2. What line is the error on? What type of error is it?
  3. Fix it, save, and run again.
🤔 What was the bug?
Line 4 has a SyntaxError — there's a missing comma between "Total cost:" and total inside print(). The fix: print("Total cost:", total).
🌟 Debugging Strategy

Every time you get an error:
1. DON'T PANIC — errors are normal.
2. Read the last line of the traceback — it tells you the type of error.
3. Find the line number — go to that line in VS Code.
4. Look carefully at that line — the problem is there (or very close by).
5. Fix, save, run again.


Understanding Data Types Deeply

Python automatically figures out the type of data — you don't have to tell it. But understanding types is crucial because certain operations only work with certain types.

💡 Python Infers the Type Automatically

In some languages, you have to say "this is a number" or "this is text" explicitly. In Python, you just write the value and Python figures it out: x = 10 → Python sees a whole number → type is int. y = 3.14 → Python sees a decimal → type is float. z = "hello" → Python sees quotes → type is str. You can always check the type using type().

TASK 6.1 Checking Data Types with type()

Create types.py:

PYTHONtypes.py
a = 42 b = 3.14 c = "Hello" d = "100" print(a, "→ type:", type(a)) print(b, "→ type:", type(b)) print(c, "→ type:", type(c)) print(d, "→ type:", type(d))
Output
42 → type: <class 'int'> 3.14 → type: <class 'float'> Hello → type: <class 'str'> 100 → type: <class 'str'>

Look at d: the value "100" is a string (text), not a number — because it has quotes around it. 100 (no quotes) would be an int. Quotes make all the difference!

TASK 6.2 Operations That Don't Mix

Create type_mix.py:

PYTHONtype_mix.py
# These work: print(10 + 5) # int + int → addition → 15 print(10 + 2.5) # int + float → addition → 12.5 print("Hi" + " there") # str + str → concatenation → "Hi there" print("Ha" * 3) # str * int → repetition → "HaHaHa" # This does NOT work: # print("age: " + 20) # str + int → TypeError! # print("hello" - "h") # str - str → TypeError! (subtraction makes no sense for text)
  1. Run the code as-is. Notice the working operations.
  2. Now uncomment the line # print("age: " + 20) (remove the # at the start). Save and run. Read the error.
  3. Comment it back (add #) and uncomment the other line to see that error too.

💡 Converting Between Types

You can convert values between types:
str(42) → converts the number 42 to the text "42"
int("42") → converts the text "42" to the number 42
float("3.14") → converts the text "3.14" to the number 3.14
int(3.9) → converts float to int (drops the decimal) → 3

Remember from Day 2: input() always gives a string. To do math with user input, you must convert it: int(input("Enter a number: "))

📝 Quiz

What is the type of "3.14" (with quotes)?

A str (string)
B float
C int
D number
Correct! Anything inside quotes is a string, even if it looks like a number. "3.14" is text. 3.14 (no quotes) is a float.
📝 Quiz

What does int(7.9) return?

A 8
B 7.9
C Error
D 7
Correct! int() drops everything after the decimal point — it does NOT round. int(7.9) gives 7, not 8.

Methods — Actions on Data

Values in Python aren't just passive data — they come with built-in actions you can perform on them. These actions are called methods.

🏠 Real-World Analogy

Think of a phone. A phone is an object. It can do things: make a call, send a text, take a photo. Those are its methods — actions the phone can perform. Similarly, a Python string can do things: make all letters uppercase, replace a word, count how many times a letter appears. You call a method using a dot: phone.take_photo()"hello".upper().

TASK 7.1 String Methods

Create methods.py:

PYTHONmethods.py
text = " Hello, Python World! " print(text.upper()) # ALL CAPS print(text.lower()) # all lowercase print(text.strip()) # remove spaces from both ends print(text.replace("Python", "Awesome")) # swap words print(text.count("l")) # how many times "l" appears print(text.startswith(" H")) # does it start with " H"? print(len(text)) # length (total characters)
Output
HELLO, PYTHON WORLD! hello, python world! Hello, Python World! Hello, Awesome World! 2 True 24

The pattern is always: variable.method(). The dot (.) connects the variable to the action. Some methods need extra information inside the parentheses (like .replace("old", "new")), some don't (like .upper()).

TASK 7.2 Number Methods & Built-in Functions

Create num_methods.py:

PYTHONnum_methods.py
x = -15 y = 3.789 print(abs(x)) # absolute value → 15 print(round(y)) # round to nearest whole number → 4 print(round(y, 1)) # round to 1 decimal place → 3.8 print(max(10, 25, 7)) # largest value → 25 print(min(10, 25, 7)) # smallest value → 7
  1. Type, save, run. Compare each output with the comment.
  2. Note: abs(), round(), max(), min() are built-in functions (not methods). You write abs(x) not x.abs(). The difference isn't important now — just know they exist.
📝 Quiz

What does "hello world".replace("world", "python") return?

A "hello world"
B "world python"
C "hello python"
D Error
Correct! .replace("world", "python") finds "world" in the string and swaps it with "python", giving "hello python".

Practice Exercises

Time to put everything together. There are three types of exercises: Fill-in (complete the missing part), Debug (find and fix the error), and Write (write from scratch). Create a new file for each exercise.

✏️ Fill-in Exercises

✏️ Exercise F1 — Swap the Greeting

Complete the code so it prints Hi, Pooja!

PYTHONex_f1.py
name = "Pooja" greeting = "Hi, " + ??? + "!" print(greeting)
name — The blank should be the variable name which holds "Pooja". Concatenation joins them: "Hi, " + "Pooja" + "!""Hi, Pooja!"
✏️ Exercise F2 — Calculate Area

Complete the code so it prints the area of a rectangle (width × height):

PYTHONex_f2.py
width = 12 height = 5 area = ??? print("Area:", area)
area = width * height — This calculates 12 * 5 and stores 60 in area.
✏️ Exercise F3 — Convert and Add

The variable user_input is a string. Complete the code to convert it to a number and add 10:

PYTHONex_f3.py
user_input = "25" number = ???(user_input) result = number + 10 print(result)
intint(user_input) converts the string "25" to the integer 25. Then 25 + 10 = 35.
✏️ Exercise F4 — Make Uppercase

Complete the code so it prints PYTHON IS FUN:

PYTHONex_f4.py
text = "python is fun" loud = text.???() print(loud)
uppertext.upper() converts all characters to uppercase.

🐛 Debug Exercises

For each exercise: create the file, run it, read the traceback, find the line, fix the bug. Only then check the answer.

🐛 Exercise D1 — NameError
PYTHONex_d1.py
1 username = "Pooja" 2 greeting = "Welcome, " + Username 3 print(greeting)
Line 2 — NameError. Python is case-sensitive! Username (capital U) is NOT the same as username (lowercase u). Fix: change Username to username on line 2.
🐛 Exercise D2 — SyntaxError
PYTHONex_d2.py
1 price = 49.99 2 tax = 5.0 3 total = price + tax 4 print("Total: " + total)
Line 4 — TypeError. "Total: " is a string and total is a float. You can't + them. Fix: print("Total: " + str(total)) or simpler: print("Total:", total).
🐛 Exercise D3 — SyntaxError
PYTHONex_d3.py
1 name = "Alice" 2 age = 30 3 print("Name:", name 4 print("Age:", age)
Line 3 — SyntaxError. Missing closing parenthesis ) at the end of line 3. Fix: print("Name:", name). Python sees line 4 and gets confused because line 3 wasn't finished.
🐛 Exercise D4 — TypeError
PYTHONex_d4.py
1 num1 = input("Enter a number: ") 2 num2 = input("Enter another: ") 3 total = num1 + num2 4 print("Sum:", total)

Hint: Enter 10 and 20. Does it show 30 or something else?

Not a crash, but a logical bug! It prints 1020 instead of 30. input() returns strings, so "10" + "20" = "1020" (concatenation, not addition). Fix: num1 = int(input("Enter a number: ")) and same for num2.
🐛 Exercise D5 — Multiple Bugs
PYTHONex_d5.py
1 product = "Laptop" 2 price = "75000" 3 discount = 5000 4 final_price = price - discount 5 print(Product, "costs", final_price)

Hint: There are two bugs. Fix the first, run again, then fix the second.

Bug 1 — Line 4, TypeError: price is a string "75000" (it has quotes!). You can't subtract a number from a string. Fix: change line 2 to price = 75000 (remove quotes).
Bug 2 — Line 5, NameError: Product (capital P) should be product (lowercase p). Python is case-sensitive.
🐛 Exercise D6 — Tricky String Bug
PYTHONex_d6.py
1 sentence = "She said "hello" to me" 2 print(sentence)
Line 1 — SyntaxError. The quotes inside the string confuse Python — it thinks the string ends at "She said ". Fix: use single quotes outside: sentence = 'She said "hello" to me', or escape the inner quotes: sentence = "She said \"hello\" to me".

🚀 Write-from-Scratch Exercises

WRITE W1 Temperature Converter

Write a program in ex_w1.py that:

  1. Creates a variable celsius with the value 37
  2. Calculates the Fahrenheit equivalent using the formula: fahrenheit = (celsius * 9/5) + 32
  3. Prints: 37 °C = 98.6 °F
celsius = 37
fahrenheit = (celsius * 9/5) + 32
print(celsius, "°C =", fahrenheit, "°F")
WRITE W2 Personal Info Card

Write a program in ex_w2.py that:

  1. Stores your name, age, and city in three separate variables
  2. Creates a bio variable that concatenates them into one sentence like "My name is Pooja, I am 20 years old, from Mumbai." (Hint: you'll need str() for the age)
  3. Prints bio in uppercase using a string method
name = "Pooja"
age = 20
city = "Mumbai"
bio = "My name is " + name + ", I am " + str(age) + " years old, from " + city + "."
print(bio.upper())
WRITE W3 Word Counter

Write a program in ex_w3.py that:

  1. Creates a variable sentence with the value "I am learning Python and it is exciting"
  2. Prints how many characters are in the sentence (use len())
  3. Prints how many times the letter "i" appears (use .count())
  4. Prints the sentence with all "Python" replaced by "programming"
sentence = "I am learning Python and it is exciting"
print("Length:", len(sentence))
print("Count of 'i':", sentence.count("i"))
print(sentence.replace("Python", "programming"))

🐛 More Debug Challenges

🐛 Exercise D7 — Method Error
PYTHONex_d7.py
1 text = "hello world" 2 print(text.Upper())
Line 2 — AttributeError. Python is case-sensitive — the method is .upper() (all lowercase), not .Upper(). Fix: print(text.upper()).
🐛 Exercise D8 — Wrong Type for Method
PYTHONex_d8.py
1 score = 95 2 print(score.upper())
Line 2 — AttributeError. .upper() is a string method — it only works on strings, not on integers. score is 95 (an int). It doesn't make sense to "uppercase" a number. Fix depends on intent: if you want to print the number, just use print(score). If you want it as text, print(str(score)).
🐛 Exercise D9 — The Silent Bug

This code runs without errors but gives the wrong answer. Expected output: Average: 20.0

PYTHONex_d9.py
1 a = 10 2 b = 20 3 c = 30 4 average = a + b + c / 3 5 print("Average:", average)
Line 4 — Logic Error (wrong output: 40.0 instead of 20.0). Python follows math order of operations: division happens before addition. So a + b + c / 3 means 10 + 20 + (30/3) = 10 + 20 + 10 = 40.0. Fix: add parentheses: average = (a + b + c) / 3.
🐛 Exercise D10 — Variable Update Bug

Expected output: Final balance: 1200

PYTHONex_d10.py
1 balance = 1000 2 deposit = 500 3 withdrawal = 300 4 balance = balance + deposit 5 balance = balance + withdrawal 6 print("Final balance:", balance)
Line 5 — Logic Error. It says balance + withdrawal but a withdrawal should subtract. Fix: change line 5 to balance = balance - withdrawal. Then: 1000 + 500 - 300 = 1200.

Completion Checklist

🎯 I Can Now…

🏆

Incredible Progress!

You set up a professional coding workspace, learned how Python stores data, and — most importantly — you learned how to read errors and debug code. That last skill alone puts you ahead of most beginners. Next time, we'll learn about conditions (if/elif/else), loops, and start building more complex programs.