




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Practice paper for computer science student
Typology: Schemes and Mind Maps
1 / 311
This page cannot be seen from the preview
Don't miss anything!





























































































KENDRIYA VIDYALAYA SANGATHAN,
एना[ कुलम ¢ेğ
ERNAKULAM REGION
2022
23
CHIEF PATRON
Mr R Senthil Kumar
Deputy Commissioner
KVS RO Ernakulam
PATRON
Mrs Deepti Nair
Assistant Commissioner
KVS RO Ernakulam
PRINCIPAL IN-CHARGE
Mr Alex Jose
Principal I/C, K V Konni
CONTENT AND REVIEW
Mrs. VIDYA R PRABHU, K V NO.1 PALAKKAD (CO-ORDINATOR)
Mr. SREEJITH T, K V NO.2 KASARAGOD
Mrs. REENA P V, K V PAYYANUR
Mrs. BINDHIYA N, K V KELTRON NAGAR
Mrs. REKHA C, K V KANNUR
Mrs. ANJANA K K, K V NO.2 CALICUT
Mr. ARUN PRASANTH, K V KANJIKODE
Mrs. LATHA RAMAKRISHNAN, KV NO2. KOCHI
Mrs. SREELEKSHMI S, K V ADOOR (SHIFT 1)
Mrs. LIJINA T, K V AKKULAM
Mrs. HARIPRIYA NAIR KV PANGODE
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 1
LET US REVISE THE CONCEPTS THAT WE LEARNED IN CLASS XI
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 3
The data stored in memory can be of many types. For example, a student roll number is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. Some are mutable and some are immutable.
Numeric Types: int, float, complex Boolean – True or False values. Used when comparisons are made and the result can be expressed as True or False None – a special type with an unidentified value or absence of value. Sequence: an ordered collection of elements. String, List and Tuples are sequences. Items/elements are Identified by its index. Sets – an unordered collection of any type without duplicate entry. Mappings – Dictionaries are mappings. Elements of dictionaries are key-value pairs. Keys are used to access values. Keys are immutable.
Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables.
If the values can be changed after creating the variable and assigning values, then it is called mutable. If the value assigned cannot be changed after creating and initializing it, then it is known as Immutable. When an attempt is made to update the immutable type, a new memory location is used with name remaining the same.
Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The assignment operator (=) is used to assign values to variables. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. For example – a= 100 #an integer is signed b = 1000.0 # A floating point value c = "John" # A string d = ‘’’ Hello world good morning’’’ # multi line string
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 4
Python allows you to assign a single value to several variables simultaneously.
For example: a = b = c = 1 Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables.
For example − a,b,c = 1,2,"kvsch“ Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively, and one string object with the value "john" is assigned to the variable c. Also, it is possible to define and initialize multiple variables with different values as given below a, b, c = 5,10, The above instruction will create three variables named a,b,c and initialize them with values 5, 10 20 respectively.
The Python print statement is often used to output variables.Variables do not need to be declared with any particular type. Different type of data can be assigned even after initializing them with some type of data. x = 5 # x is of type int x = "kve " # x is now of type str print(x) Output: kve
To combine both text and a variable, Python uses the “+” character: Example x = "awesome" print("Python is " + x) Output of the above code is: Python is awesome
You can also use the + character to add a variable to another variable: Example x = "Python is " y = "awesome" z = x + y print(z) Output: Python is awesome
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 6
Binary right shift >>
and &
or \
Less than <
Greater than >
Less than or equal to <=
Greater than or equal to >=
Check equality ==
Check not equal !=
A statement is an instruction that the Python interpreter can execute. We have normally two basic statements, the assignment statement and the print statement. Some other kinds of statements that are if statements, while statements, and for statements generally called as control flows.
Examples: An assignment statement creates new variables and gives them values:
>>> x= >>> school="kve"
A ‘print’ statement is to display something on the screen/monitor. We use the print()
function for this purpose. And input() function is used to receive the input from the user
through the keyboard.
Operator precedence affects how an expression is evaluated. Each operator is having a priority when used in an expression in combination with other operators. For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first multiplies 32 and then adds into 7. Example 1: >>> 3+42 11 Multiplication gets evaluated before the addition operation
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 7
Parentheses () overriding the precedence of the arithmetic operators
Example 2: a = 20 b = 10 c = 15 d = 5 e = 0
e = (a + b) * c / d #( 30 * 15 ) / 5 print("Value of (a + b) * c / d is ", e) e = ((a + b) * c) / d # (30 * 15 ) / 5 print("Value of ((a + b) * c) / d is ", e) e = (a + b) * (c / d) # (30) * (15/5) print("Value of (a + b) * (c / d) is ", e)
e = a + (b * c) / d; # 20 +(150/5) print("Value of a + (b * c) /d is", e)
Output: Value of (a + b) * c / d is 90. Value of ((a + b) * c) / d is 90. Value of (a + b) * (c / d) is 90. Value of a + (b * c) /d is 50.
Comments are discarded by the Python interpreter. Comments acts as some message to the Programmer. It can be used as documents.
Single-line comments begins with a hash(#) symbol and is useful in mentioning that the whole line should be considered as a comment until the end of line. A Multi line comment is useful when we need to comment on many lines. In python, triple double quote(“ “ “) and single quote(‘ ‘ ‘)are used for multi-line commenting. Example:
‘’’ I am a multi line comment’’’
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 9
Value Error: In Python, a value is the information that is stored within a certain object. To encounter a ValueError in Python means that is a problem with the content of the object you tried to assign the value to.
Python has many built-in exceptions which forces your program to output an error when something in it goes wrong. In Python, users can define such exceptions by creating a new class. This exception class has to be derived, either directly or indirectly, from Exception class. Different types of exceptions: ArrayIndexOutOfBoundException. ClassNotFoundException. FileNotFoundException. IOException. InterruptedException. NoSuchFieldException. NoSuchMethodException
Python module can be defined as a python program file which contains a python code including python functions, class, or variables. In other words, we can say that our python code file saved with the extension (.py) is treated as the module. We may have a runnable code inside the python module. A module in Python provides us the flexibility to organize the code in a logical way. To use the functionality of one module into another, we must have to import the specific module.
Syntax: import Every module has its own functions, those can be accessed with. (dot) Note: In python we have help ()
Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". Some of the modules like os, date, and calendar so on……
>>> import sys >>> print (sys.version) 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
>>> print(sys.version_info)
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 10
sys.version_info(major=3, minor=8, micro=0, release level='final', serial=0)
>>> print(calendar.isleap(2020)) True >>> print(calendar.isleap(2017)) False
Control Structures
Flow of execution means the way in which the instructions are executed. It can be
Selection or Conditional statements helps us to execute some statements based on whether the condition is evaluated to True or False.
Use of if statement: The if statement contains a logical expression using which data is compared and a decision is made based on the result of the comparison.
Syntax: if : statement(s)
If the boolean expression evaluates to TRUE, then the block of statement(s) inside the if statement is executed. If boolean expression evaluates to FALSE, then the first set of code after the end of the if statement(s) is executed.
Flow chart representing the execution of ‘if’ statement:
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 12
Flow Chart:
Example of if - else: a=int(input('enter the number')) if a>5: print("a is greater") else: print("a is smaller than the input given") Output: enter the number 2 a is smaller than the input given
a=10 b= if a>b: print("A is Greater than B") else: print("B is Greater than A")
Output: B is Greater than A
The elif statement allows us to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE. Similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if.
KVS RO EKM - STUDENT SUPPORT MATERIAL (COMPUTER SCIENCE-083) FOR THE ACADEMIC YEAR 2022- 23 13
Syntax of if – elif - else : If : Body of if stmts elif < test expression>: Body of elif stmts else: Body of else stmts
Flow Chart:
Example of if - elif – else: a=int(input('enter the number')) b=int(input('enter the number')) c=int(input('enter the number')) if a>b: print("a is greater") elif b>c: print("b is greater") else: print("c is greater") Output: enter the number 5 enter the number 2 enter the number 9 a is greater >>> enter the number 2