Informatics Practices · Class 11 Optional
Ch 3Brief Overview of Python — Class 11 Informatics Practices, concept-first.
A computer, by itself, does nothing. It acts only when it is given instructions — and those instructions must be arranged in a definite order, because the machine executes them one after another. An ordered set of instructions or commands given to a computer for execution is called a program.
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
Variable Type Identification
You walk into a room. You see a chair, a table, a cup of water, and a person. Without thinking, you know: the chair is for sitting, the cup holds liquid, the person can talk.
Most relevant Q&A
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction to Python
A computer, by itself, does nothing. It acts only when it is given instructions — and those instructions must be arranged in a definite order, because the machine executes them one after another.
Working with Python
Writing a Python program is only half the job — something must read those statements and make the computer carry them out. That something is the Python interpreter.
Execution Modes
The Python interpreter can be put to work in two distinct ways, and choosing between them is the first practical decision every programmer makes.
Python Keywords
Every language — human or programming — has a small set of words whose meaning is fixed in advance. In Python, these are called keywords: reserved words that carry a specific, built-in meaning for the…
Identifiers
A program constantly refers to things — a variable that holds marks, a function that computes an average, or some other entity defined in the code.
Variables
A variable is an identifier whose value can change during the life of a program. The name stays fixed; what it refers to may vary.
Data Types
Every value that appears in a Python program — a number, a name, a price, a list of cities — belongs to a specific data type.
Number
The Number data type is Python's home for numerical values — it stores numbers and nothing else. Within this one family, Python distinguishes three different types, because whole numbers, decimal numb…
Sequence
2 QA sequence in Python is an ordered collection of items in which each item is indexed by an integer value. Both halves of that definition matter.
+−Worked Examples1 question
Mapping
Sequences store items by position; a mapping stores items by name. Mapping is an unordered data type in Python — its items are not kept at numbered positions the way string, list and tuple elements ar…
Operators
Every program ultimately does two things: it stores values, and it does something with them. The "doing something" part is the job of operators.
Arithmetic Operators
Arithmetic operators are the workhorses of everyday computation. Python supports operators for the four basic arithmetic operations — addition, subtraction, multiplication and division — and adds thre…
Relational Operators
Arithmetic operators produce a new value; relational operators produce a verdict. A relational operator compares the values of the operands on its two sides and determines the relationship between the…
Assignment Operators
A variable is only useful if you can put a value into it — and change that value later. That is exactly what an assignment operator does: it assigns a value to the variable on its left, or changes the…
Logical Operators
Relational operators give single verdicts — True or False. Real conditions, though, are rarely single: "the marks are above 90 AND attendance is above 75", "the day is Saturday OR Sunday".
Membership Operators
Very often a program needs to ask a simple question about a collection: is this value inside it, or not? Membership operators answer exactly that.
Expressions
Constants store fixed values, variables store changeable ones, and operators act on them — an expression is where all three come together.
Precedence of Operators
3 QWhen an expression contains more than one operator, Python must decide which operation to perform first — and the answer changes the result.
+−Worked Examples1 question
+−Worked Examples1 question
+−Worked Examples1 question
Input and Output
3 QA program becomes genuinely useful the moment it can talk to its user — accept data while it runs and show results back.
+−Worked Examples1 question
+−Worked Examples1 question
+−Worked Examples1 question
Debugging
No matter how carefully a program is written, mistakes creep in — and a mistake, or error, can hurt a program in two distinct ways.
Syntax Errors
Every programming language, Python included, has rules that determine how a program must be written — which symbols go where, what a valid statement looks like.
Logical Errors
A logical error — also called a bug, or a semantic error — is the sneakiest of the three error types, because it does not stop the program at all.
Runtime Error
A runtime error occupies the middle ground between a syntax error and a logical one: the statement is perfectly correct syntactically, so the program starts executing — but at some point the interpret…
Functions
When the same task has to be performed again and again in a program, writing the same statements repeatedly is wasteful and error-prone.
if..else Statements
2 QOrdinarily the statements of a program execute one after another, top to bottom. But real problems often present a choice: depending on the outcome of some condition, the program should do one thing r…
+−Worked Examples1 question
For Loop
Programs frequently need to do the same thing many times over. Think of a program that has to display the attendance of every student of a class: the print statement must execute once for each student…
The range() Function
A for loop is only as useful as the sequence it walks through, and Python supplies a built-in function whose whole job is to manufacture sequences of integers on demand: range().
Nested Loops
A loop may itself contain another loop inside its body. A loop written inside another loop is called a nested loop.
Summary
- Python is an open-source, high-level, interpreter-based language, suitable for both scientific and non-scientific computing tasks.
Exercises
+−Show 11 questionsHide questions11 questions
- Q1Which of the following identifier names are invalid and why? a) Serial_no. b) 1st_Room c) Hundred\$ d) Total Marks e) Total_Marks f) total-M…Free
- Q2Write the corresponding Python assignment statements: a) Assign 10 to variable length and 20 to variable breadth. b) Assign the average of v…Free
- Q3Which data type will be used to represent the following data values and why? a) Number of months in a year b) Resident of Delhi or not c) Mo…Free
- Q4Give the output of the following when num1 = 4, num2 = 3, num3 = 2 a) num1 += num2 + num3 b) print (num1) c) num1 = num1 ** (num2 + num3) d)…Preview
- Q5Categorise the following as syntax error, logical error or runtime error: a) 25 / 0 b) num1 = 25; num2 = 0; num1/num2Preview
- Q6Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate = R% per…Preview
- Q7Write a program to repeat the string "GOOD MORNING" n times. Here n is an integer entered by the user.Preview
- Q8Write a program to find the average of 3 numbers.Preview
- Q9Write a program that asks the user to enter one's name and age. Print out a message addressed to the user that tells the user the year in wh…Preview
- Q10What is the difference between else and elif construct of if statement?Preview
- Q11Find the output of the following program segments: a) for i in range(20,30,2): print(i) b) country = 'INDIA' for i in country: print (i) c)…Preview