BORING EDUCATION — LIVE EXPERIMENTProduct is live. Experiments are running. Feedback is being collected. Improvements are underway.Welcome to Boring Education. We're glad you're here while we're figuring out how to make learning better.
BORINGEDUCATION

Python Basics: Variables, Data Types and Input/Output: PECTAA Class 11 Computer Science, Punjab Board

21 October 2026

A program that cannot remember anything or talk to its user is not much use. Variables give it memory, input() lets it listen, and print() lets it answer. These three ideas open Chapter 2 of the book and run through every Python program you will write this year.

Chapter 2 of the PECTAA Computer Science 11 book is Python Programming. Sections 2.1 and 2.2 introduce programming, the Python development environment, basic syntax, variables, data types and input/output. This note is for FSc Part 1 (1st year, Class 11) students in Lahore, Faisalabad, Sargodha, Rawalpindi, Multan, Gujranwala and the other Punjab boards. Gujrat district comes under the Gujranwala board. PECTAA writes the books. Your own board sets your paper.

What to know

Why Python (section 2.1). Python is versatile and used in web development, data analysis and other fields. Its simple syntax and clear structure let beginners focus on programming ideas rather than complex rules.

Programming basics (section 2.1.1). Computer programming is creating a set of instructions that tell a computer how to do a task, written in a language the computer can understand and run. The basic steps:

  1. Write code in a programming language.
  2. Compile or interpret it into a form the computer understands.
  3. Execute it to perform the task.
  4. Output the results or carry out actions.

Development environment (section 2.1.1.2). Setting up means preparing a computer to write, run and debug Python: installing and configuring Python and any tools and libraries needed. An IDE makes coding easier, and online services can also write and run Python programs.

Basic syntax (section 2.2). The book's first program is a single line:

print("This is my first page")

The print function displays the text inside the quotation marks.

Comments. Comments are lines the interpreter does not execute; they explain the code. A single-line comment starts with #. For longer notes, the book places text between triple quotes at the start and end.

Variables (section 2.2.1.1). A variable is a storage container in memory for storing, retrieving and changing data. Its value can change during the program. In the book's example, age = 71 is printed in a sentence about Ahmad, then age = 60 replaces it for a sentence about Iqbal.

Naming rules (section 2.2.1.2).

  • Begin with a letter (a–z, A–Z) or an underscore (_).
  • Later characters may be letters, digits (0–9) or underscores.
  • Names are case-sensitive: age and Age are different variables.
  • Reserved keywords such as for, while and if cannot be names.

The book's tips: use meaningful names (age, not a), lowercase letters, and underscores between words (student_name).

Data types (section 2.2.1.3).

Type Stores Book example
int whole numbers age = 17
float decimal numbers a value such as 19.99
str text name = "Ali"
bool True or False is_student = True

Input and output (section 2.2.1.4).

  • input() shows a message, waits for the user to type and press Enter, and returns the text, which is stored in a variable: name = input("Enter your name:").
  • print() takes one or more arguments and displays them: print("Hello, " + name + "!").

Number inputs (section 2.2.1.5). input() gives text, so wrap it in int() or float():

  • user_age = int(input("Enter your age:"))
  • user_height = float(input("Enter your height in meters:"))

Key points

  • A variable gets its value with =, and a new assignment replaces the old value.
  • Python decides the type from the value: 17 is int, 17.0 is float, "17" is str.
  • input() always returns a string.
  • Comma-separated print arguments are shown with spaces between them; + joins strings with no extra space.

Worked examples

Example 1 (book variable example).

age = 71
print("Ahmad lived for", age, "years")
age = 60
print("Iqbal lived for", age, "years")

Output: Ahmad lived for 71 years, then Iqbal lived for 60 years. The same variable holds two values at different times.

Example 2 (valid or invalid names).

  1. student_name: valid.
  2. _total: valid; it starts with an underscore.
  3. 2nd_mark: invalid; it starts with a digit.
  4. while: invalid; it is a keyword.
  5. Age and age: both valid, and different.

Example 3 (number input). The user types 17 at user_age = int(input("Enter your age:")). Without int(), the stored value would be the text "17". With int(), it is the whole number 17, so user_age + 1 gives 18.

Common mistakes in the exam

  1. Starting a name with a digit. 1st_name is not allowed.
  2. Forgetting conversion. input() returns a string; adding 1 to it raises an error.
  3. Joining a number with +. "Age: " + 17 fails; use a comma or str(17).
  4. Writing True as "True". With quotes it is a string, not a Boolean.
  5. Assuming case does not matter. Name and name are different variables.

Exam technique

  • When asked for output, trace the program line by line and write each printed line separately.
  • For naming questions, quote the rule that each invalid name breaks.
  • Write code in small, clearly indented blocks and keep quotation marks matched.
  • Check your board's notice for the sections in your paper.

Practice questions

  1. Name the data type of 3.5, "Lahore", 42 and False. Answer: float, str, int, bool.
  2. Is my-score a valid variable name? Answer: No. A hyphen is not allowed; use my_score.
  3. What does print("Sum:", 4 + 5) display? Answer: Sum: 9.
  4. Write a line that reads a decimal height from the user. Answer: height = float(input("Enter height:")).
  5. Which symbol starts a single-line comment? Answer: The # symbol.

Ready to practise this? Continue in 1st Year Computer Science.

Quick answers

What is a variable in Python?

A storage container in the computer's memory that allows data to be stored, retrieved and changed. Its value can change while the program runs.

What are the variable naming rules in Python?

A name must begin with a letter (a–z, A–Z) or an underscore; later characters can be letters, digits or underscores; names are case-sensitive; and reserved keywords such as for, while and if cannot be used.

Which data types does the book introduce first?

Integer (int) for whole numbers, floating-point (float) for decimals, string (str) for text and Boolean (bool) for True or False.

Why do we write int(input(...)) for numbers?

input() always returns text. int() or float() converts that text into a number so it can be used in calculations.

Which board sets my paper if I study in Gujrat?

Gujrat district is listed under the Board of Intermediate and Secondary Education, Gujranwala. PECTAA writes the books. Your board sets the paper and the dates, so follow its notices.

Learn this properly, step by step, free.

Continue in 1st Year Computer Science

Free right now. No ads. Tell us what to fix.

More notes

All notes →