Showing posts with label fixing errors. Show all posts
Showing posts with label fixing errors. Show all posts

Wednesday, September 16, 2026

Cambridge-Lower-Secondary-Computing-7-Ben-Barnes-Tristan-Kirkpatrick-Etc-Z-Library Notes Online Class Unit 7 - 1 - 2 Python Interactive Mode, Python Script Mode, IDLE, Python Variables, Print Statement, Python Comments, Fix Python Errors, ICT Programming

🐍 Python Basics: Modes, Variables & Comments

Interactive Mode, Script Mode, Error Correction, and Variables

📚 About this guide: Complete, exam-friendly notes for learning Python Programming Basics. Master the difference between Interactive and Script modes, learn how to fix errors, add comments, and use variables with the print() statement.
Concept 1

What is Interactive Mode?

When you launch Python IDLE, you see the Python Shell with the >>> prompt. This is Interactive Mode, which allows individual Python commands to be typed directly and carried out immediately.

>>> print("Hello world")
Hello world
>>> (7+6)*2
26
>>> 
          
⚠️ Important: Python is case-sensitive. You must type commands using lower-case letters (e.g., print, not Print). Also, you do not need the print command for basic calculations in the shell.
Keywords

Essential Vocabulary

  • Interactive mode: The Python shell allows commands to be entered and run immediately.
  • Python shell: The interactive mode environment where commands are typed directly.
  • Print statement: A Python command used to output text or values onto the screen.
  • Case sensitive: Able to distinguish between capital and small letters.
  • Interpreter: Translates Python code into machine code line by line.
  • Machine code: The binary language a computer uses to carry out instructions.
Practice

Interactive Mode Practice Tasks

  • Enter: print("Welcome to the Python Shell")
  • Enter a command to print your name: print("Your Name")
  • Fix the error: print("Hello World) (Missing closing quotation mark).
  • Fix the calculation: (7+3*2 is missing a bracket. Correct it to (7+3)*2 to get 20.
  • Try four of your own math commands (remember * is for multiplication).
  • Get Python to add 150 and 23, then multiply by 3: (150 + 23) * 3
Concept 2

What is Script Mode?

In Interactive Mode, code cannot be saved. Script Mode uses a text editor (like Notepad) to write, save, and run multiple lines of code as a complete program.

Steps to Create & Run:

  1. Create: In the Python shell, select File → New File.
  2. Type: Enter your code (e.g., print("Hello world")).
  3. Save: Select File → Save As. Name it HelloWorld.py (the .py extension is required).
  4. Run: Select Run → Run Module (or press F5). The output appears in the Shell window.
Concept 3

Correcting Errors in Script Mode

If there is an error, Python highlights it in red and provides an error message.

Print("Hello World")
# Error: NameError: name 'Print' is not defined
          

How to fix: Open the program, correct the mistake (change Print to print), save, and run again.

Concept 4

Adding Comments

Comments explain what the code does. The Python interpreter ignores them. Start a comment with a hash (#) symbol.

# This is an Adventure Game about The Digital Sweet Shop
# The program was written by me

print("Welcome to The Digital Sweet Shop")
print() # This prints a blank line
          
Keywords

Script Mode Vocabulary

  • Script mode: Python's text editor, allowing programmers to enter a list of commands executed together.
  • Execute: Another word for running a program.
  • Comments: Text entered by a programmer to improve code readability; starts with # in Python.
Practice

Hands-On Practice Tasks

  • Create a New File in IDLE.
  • Type: print("Welcome to my first program in Python")
  • Add a line to print your favourite hobby.
  • Save as My First Program.py and Run (F5).
  • Add these lines:
    print("Did you know Python can do calculations? The line below displays 10")
    print(7+3)
    print("How about this? The calculation below should display 25")
    print(7+3*2+5)
                  
  • Fix the error: The last line outputs 18, not 25. Correct it to print((7+3)*2+5) and add a # comment above it explaining the BIDMAS/PEMDAS fix.
  • New Program: Create Maths Favourites.py that prints your name, favourite number, and favourite calculation (e.g., "Name: Adnan", "Favourite number: 7", "Favourite calculation: multiplication").
Concept 5

What is a Variable?

A variable is a named location in the computer's memory that stores data of a particular type. Data can be assigned directly in the code or from user input.

name = "Ardeel"
age = 12
address = "Station Road"
colour = "Red"
          
Concept 6

Printing with Variables

To print a variable alongside text, do not put the variable name in quotation marks. Use a comma to join the text and the variable.

print(name)
# Output: Ardeel

print("Your name is", name)
# Output: Your name is Ardeel

print("Your name is", name, ". Nice to meet you.")
# Output: Your name is Ardeel . Nice to meet you.
          
🔑 Keyword:
  • Variable: A named memory location used to store data of a given type during program execution; a variable can change value as the program runs.
Practice

Variable Practice Tasks

  • Create a new file and type:
    name = "Ardeel"
    age = 12
    address = "Station Road"
    colour = "Red"
    print("Your name is", name)
                  
  • Add code to display the age: print("You are", age, "years old")
  • Complete the program to say: print("You live at", address)
  • Complete the program to say: print(colour, "is your favourite colour")
  • Final Task: Create a new program showing your name, age, address, and favourite colour. Save and run it.

❓ Frequently Asked Questions (FAQ)

Q: What is the difference between Python Interactive Mode and Script Mode? A: Interactive Mode (Python Shell) allows you to type and execute single lines of code immediately, but they cannot be saved. Script Mode uses a text editor to write, save (.py), and run multiple lines of code as a complete program.
Q: What is a variable in Python? A: A variable is a named location in the computer's memory used to store data of a particular type. Variables can change their value as the program runs.
Q: How do you add comments in Python? A: In Python, you add comments by starting a line with a hash (#) symbol. The Python interpreter ignores any text on a line after the # symbol, making it useful for explaining code.
Q: Why is Python considered case-sensitive? A: Python is case-sensitive, meaning it distinguishes between uppercase and lowercase letters. For example, 'print' is a valid command, but 'Print' will cause a NameError.