techtipnow

Python Revision Tour Class 12 Notes | CBSE Computer Science

Python Revision Tour Class 12 Notes covers Python Fundamentals of class 11 including Variables, Operators, Input and Output, Flow of control, Expressions, Type Casting, Strings, List, Tuples, Dictionary. All the concepts are explained with examples so that students can build strong foundation in Python Programming Fundamentals.

  • 1 Getting Started with Python
  • 5 Dictionary

Getting Started with Python

Python is a General Purpose high level Programming language used for developing application softwares.

Features of Python

  • Free and Open Source
  • Case Sensitive
  • Interpreted
  • Plateform Independent
  • Rich library of functions
  • General Purpose

Working with Python

To write and run python programs we need Python Interpreter also called Python IDLE.

Execution Mode

We can use Python Interpreter in two ways:

  • Interactive mode
  • Script mode

Interactive Mode

  • Instant execution of individual statement
  • Convenient for testing single line of code
  • We cannot save statements for future use

Script Mode

  • Allows us to write and execute more than one Instruction together.
  • We can save programs (python script) for future use
  • Python scripts are saved as file with extension “.py”

How to execute or run python program

  • Open python IDLE
  • Click ‘File’ and select ‘New’ to open Script mode
  • Type source code and save it
  • Click on ‘Run’ menu and select ‘Run Module’

python revision tour class 12 pdf

Python Keywords

  • These are predefined words which a specific meaning to Python Interpreter.
  • These are reserve keywords
  • Keywords in python are case sensitive

python revision tour class 12 pdf

Identifiers are name used to identify a variable, function or any other entities in a programs.

Rules for naming Identifier

  • The name should begin with an alphabet or and underscore sign and can be followed by any combination of charaters a-z, A-Z, 0-9 or underscore.
  • It can be of any length but we should keep it simple, short and meaningful.
  • it should not be a python keyword or reserved word.
  • We cannot use special symbols like !, @, #, $, % etc. in identifiers.
  • It can be referred as an object or element that occupies memory space which can contain a value.
  • Value of variable can be numeric, alphanumeric or combination of both.
  • In python assignment statement is used to create variable and assign values to it.

These are keywords which determine the type of data stored in a variable. Following table show data types used in python:

python revision tour class 12 pdf

  • These are statement ignored by python interpreter during execution.
  • It is used add a remark or note in the source code.
  • It starts with # (hash sign) in python.

These are special symbols used to perform specific operation on values. Different types of operator supported in python are given below:

  • Arithmetic operator
  • Relational operator
  • Assignment operator
  • Logical operator
  • Identity operator
  • Membership operator

python revision tour class 12 pdf

Expressions

  • An expression is combination of different variables, operators and constant which is always evaluated to a value.
  • A value or a standalone variable is also considered as an expression.

56 + (23-13) + 89%8 – 2*3

Evaluation:

= 56 + (23 -13) + 89%8 – 2*3        #step1 = 56 + 10 + (89%8) – 2*3              #step2 = 56 + 10 + 1 – (2*3)                     #step3 = (56 + 10) + 1 – 6                        #step4 = (66 + 1) – 6                                 #step5 = 67 – 6                                          #step6 = 61

A statement is unit of code that the python interpreter can execute.

var1 = var2                                         #assignment statement x = input (“enter a number”)      #input statement print (“total = “, R)                           #output statement

How to input values in python?

In python we have input() function for taking user input.

Input([prompt])

How to display output in python ?

In python we have print() function to display output.

print([message/value])

Python program to input and output your name

var = input(“Enter your name”) print(“Name you have entered is “, var)

Addition of two numbers

Var1 = int(input(“enter no1”)) Var2 = int(input(“enter no2”)) Total = Var1 + Var2 Print(“Total = “, Total)

Type Conversion

Type conversion refers to converting one type of data to another type.

Type conversion can happen in two ways:

  • Explicit conversion

Implicit conversion

Explicit Conversion

  • Explicit conversion also refers to type casting.
  • In explicit conversion, data type conversion is forced by programmer in program

(new_data_type) = (expression) Explicit type conversion function

python revision tour class 12 pdf

Program of explicit type conversion from float to int

x = 12 y = 5 print(x/y)                           #output – 2.4 print(int(x/y))                    #output – 2

Program of explicit type conversion from string to int

x = input(“enter a number”) print(x+2)                                            #output – produce error “can only concatenate str to str x = int (input(Enter a number”))                           print(x+2)                                            #output – will display addition of value of x and 2

  • Implicit conversion is also known as coercion.
  • In implicit conversion data type conversion is done automatically.
  • Implicit conversion allows conversion from smaller data type to wider size data type without any loss of information

Program to show implicit conversion from int to float

var1 = 10                              #var1 is integer var2 = 3.4                             #var2 is float res  = var1 – var2              #res becomes float automatically after subtraction print(res)                             #output – 6.6 print(type(res))                                #output – class ‘Float’

  • String is basically a sequence which is made up of one or more UNICODE characters.
  • Character in string can be any letter, digit, whitespace or any other symbol.
  • String can be created by enclosing one or more characters in single, double or triple quotes.

Accessing characters in a string (INDEX)

  • Individual character in a string can be accessed using indexes.
  • Indexes are unique numbers assigned to each character in a string to identify them
  • Index always begins from 0 and written in square brackets “[]”.
  • Index must be an zero, positive or negative integer.
  • We get IndexError when we give index value out of the range.

Negative Index

  • Python allows negative indexing also.
  • Negative indices are used when you want to access string in reverse order.
  • Starting from the right side, the first character has the index as -1 and the last character (leftmost) has the index –n where n is length of string.

Is string immutable?

  • Yes, string is immutable data type. The content of string once assigned cannot be altered than.
  • Trying to alter string content may lead an error.

String operations

String supports following operations:

Concatenation

  • Concatenation refers to joining two strings.
  • Plus (‘+’) is used as concatenation operator.
  • Repetition as it name implies repeat the given string.
  • Asterisk (‘*’) is used as repetition operator.
  • Membership operation refers to checking a string or character is part or subpart of an existing string or not.
  • Python uses ‘in’ and ‘not in’ as membership operator.
  • ‘in’ returns true if the first string or character appears as substring in the second string.
  • ‘not in’ returns true if the first string or character does not appears as substring in the second string.
  • Extracting a specific part of string or substring is called slicing
  • Subset occurred after slicing contains contiguous elements
  • Slicing is done using index range like string[start_index : end_index : step_value]
  • End index is always excluded in resultant substring.
  • Negative index can also be used for slicing.

Traversing a String

  • Traversing a string refers to accessing each character of a given string sequentially.
  • For or while loop is used for traversing a string

String Functions

  • List is built in sequence data type in python.
  • Stores multiple values
  • List item can be of different data types
  • All the items are comma separated and enclosed in square bracket.
  • Individual item in a list can be accessed using index which begins from 0.

python revision tour class 12 pdf

Accessing elements in a List

  • Individual item in a list can be accessed using indexes.
  • Indexes are unique numbers assigned to each item in a list to identify them

python revision tour class 12 pdf

List is Mutable

  • Yes list is mutable.
  • Content of the list can be changed after it has been created.

python revision tour class 12 pdf

List operations

List supports following operations:

  • Concatenation refers to joining two List.
  • Concatenating List with other data type produces TypeErrors.

python revision tour class 12 pdf

  • Repetition as it name implies used to replicate a list at specified no of times.

python revision tour class 12 pdf

  • Membership operation refers to checking an item is exists in the list or not.
  • ‘in’ returns true if the item specified present in the list.
  • ‘not in’ returns true if the item specified present in the list.

python revision tour class 12 pdf

  • Extracting a subset of items from given list is called slicing
  • Subset occurred after slicing contains contiguous items.
  • Slicing is done using index range like List[start_index : end_index : step_value]
  • End index is always excluded in resultant subset of list.

python revision tour class 12 pdf

Traversing a List

  • Traversing a List refers to accessing each item a given list sequentially.
  • for or while loop can be used for traversing a list.

python revision tour class 12 pdf

List methods | List Functions

python revision tour class 12 pdf

Nested List

One list appears as an element inside another list.

python revision tour class 12 pdf

  • Tuple is built in sequence data type in python.
  • Tuple item can be of different data types
  • All the items are comma separated and enclosed in parenthesis ‘()’.
  • Individual item in a Tuple can be accessed using index which begins from 0.
  • In case of single item present in tuple, it should also be followed by a comma.
  • A sequence without parenthesis is treated as tuple by default.

python revision tour class 12 pdf

Accessing elements in a Tuple

  • Individual item in a Tuple can be accessed using indexes.
  • Indexes are unique numbers assigned to each item in a Tuple to identify them

python revision tour class 12 pdf

Tuple is Immutable

  • Yes Tuple is Immutable.
  • Content of the Tuple cannot be changed after it has been created.

python revision tour class 12 pdf

Tuple operations

Tuple supports following operations:

  • Concatenation refers to joining two Tuple.
  • Concatenation operator can also be used for extending an existing tuple.

python revision tour class 12 pdf

  • Repetition as it name implies used to repeat elements of  a Tuple at specified no of times.

python revision tour class 12 pdf

  • Membership operation refers to checking an item exists in Tuple or not.
  • ‘in’ returns true if the item specified present in the Tuple.
  • ‘not in’ returns true if the item specified present in the Tuple.

python revision tour class 12 pdf

  • Extracting a subset of items from given Tuple is called slicing
  • Slicing is done using index range like Tuple[start_index : end_index : step_value]
  • End index is always excluded in resultant subset of Tuple.

python revision tour class 12 pdf

Traversing a Tuple

  • Traversing a Tuple refers to accessing each item a given Tuple sequentially.
  • for or while loop can be used for traversing a Tuple.

python revision tour class 12 pdf

Tuple Methods and Built in Functions

python revision tour class 12 pdf

Nested Tuple

One Tuple appears as an element inside another Tuple.

python revision tour class 12 pdf

Tuple Assignment

Tuple Assignment allows elements of tuple on the left side of assignment operator to be assigned respective values from a tuple on the right side.

python revision tour class 12 pdf

  • Dictionaries are unordered collection of items falls under mapping.
  • Stores data in form of key:value pair called item.
  • Key is separated from its value by colon ‘:’ and items are separated by comma.
  • All items of dictionaries are enclosed in curly bracket ‘{}’.
  • The keys in the dictionary must be unique and should be of immutable data type.
  • The value can be repeated and of any data type.

Creating a Dictionary

python revision tour class 12 pdf

Accessing items in a Dictionary

  • Items of dictionary are accessed using keys.
  • Each key of dictionary serve as index and maps to a value.
  • If key is not present in dictionary, then we get KeyError.

python revision tour class 12 pdf

Dictionary is Mutable

Yes, Dictionary is Mutable as its content can be changed after it has been created.

Adding a new item in Dictionary

python revision tour class 12 pdf

Modifying an existing Item in Dictionary

python revision tour class 12 pdf

Traversing a dictionary

python revision tour class 12 pdf

Dictionary methods and built in functions

python revision tour class 12 pdf

1 thought on “Python Revision Tour Class 12 Notes | CBSE Computer Science”

' src=

Sir, how can I get the pdf form of your notes

Leave a Comment Cancel Reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Python Revision Tour

Class 12 - computer science with python sumita arora, multiple choice questions.

Which of the following is an invalid variable?

Reason — Variable names cannot begin with a number, although they can contain numbers.

Find the invalid identifier from the following:

Reason — break is a reserved keyword.

Which of the following is not a keyword?

Reason — eval is not a keyword in python.

Which of the following cannot be a variable?

Reason — in is a keyword in python.

Which of these is not a core data type?

Reason — Class is not a core data type.

How would you write x y in Python as an expression ?

  • none of these

Reason — ** is an arithmetic operator used for exponentiation.

What will be the value of the expression?     14 + 13 % 15

Reason — According to operator precedence remainder (%) operation will be done first and then addition (+) will be done.

14 + 13 % 15 = 14 + 13 = 27

Evaluate the expression given below if A = 16 and B = 15.     A % B // A

Reason — According to operator precedence, floor division (//) and remainder (%) both have equal precedence hence the expression will be evaluated from left to right.

A % B // A = 16 % 15 // 16 = 1 // 16 = 0

What is the value of x?     x = int(13.25 + 4/2)

Reason — According to operator precedence, division will be done first followed by addition and then it will convert to integer.

x = int(13.25 + 4/2) x = int(13.25 + 2.0) x = int(15.45) x = 15

Question 10

The expression 8/4/2 will evaluate equivalent to which of the following expressions:

Reason — As both the operators are division operators, the expression will be evaluated from left to right.

8/4/2 = 2/2 = 1.0 (8/4)/2 = 2/2 = 1.0

Question 11

Which among the following list of operators has the highest precedence?

    +, -, **, %, /, <<, >>, |

  • <<, >>

Reason — ** has highest precedence.

Question 12

Which of the following expressions results in an error?

  • float('12')
  • float('12.5')

int('12.5')

Reason — int() are positive or negative whole numbers with no decimal point.

Question 13

Which of the following statement prints the shown output below?     hello\example\test.txt

  • print("hello\example\test.txt")

print("hello\\example\\test.txt")

  • print("hello\"example\"test.txt")
  • print("hello"\example"\test.txt")

Reason — Escape sequence (\\) is used for Backslash (\).

Question 14

Which value type does input() return ?

Reason — The input() function always returns a value of String type.

Question 15

Which two operators can be used on numeric values in Python?

Reason — %, + are arithmetic operators.

Question 16

Which of the following four code fragments will yield following output?

Select all of the function calls that result in this output

  • print('''Eina \nMina \nDika''')
  • print('''EinaMinaDika''')

print('Eina\nMina\nDika')

  • print('Eina Mina Dika')
  • print('''Eina \nMina \nDika''') — It is a multiline string and by adding \n extra line will be added.
  • print('''EinaMinaDika''') — There is no new line character.
  • print('Eina\nMina\nDika') — It adds new line by \n new line character.
  • print('Eina Mina Dika') — It creates an error because it is a multiline string with no triple quotes.

Question 17

Which of the following is valid arithmetic operator in Python :

Reason — // is valid arithmetic operator in Python.

Question 18

For a given declaration in Python as s = "WELCOME", which of the following will be the correct output of print(s[1::2])?

Reason — The slicing will start from index 1 and return at every alternative step.

s[1] = E s[3] = C s[5] = M output = ECM

Question 19

Which of the following is an incorrect Logical operator in Python?

Reason — in is a membership operator.

Question 20

Which of the following is not a Tuple in Python?

  • ("One","Two","Three")

Reason — ("One") is a string data type.

Fill in the Blanks

The smallest individual unit in a program is known as a token .

A token is also called a lexical unit .

A keyword is a word having special meaning and role as specified by programming language.

The data types whose values cannot be changed in place are called immutable types.

In a Python expression, when conversion of a value's data type is done automatically by the compiler without programmer's intervention, it is called implicit type conversion .

The explicit conversion of an operand to a specific type is called type casting .

The pass statement is an empty statement in Python.

A break statement skips the rest of the loop and jumps over to the statement following the loop.

The continue statement skips the rest of the loop statements and causes the next iteration of the loop to take place.

Python's keywords cannot be used as variable name.

True/False Questions

The expression int(x) implies that the variable x is converted to integer.

Reason — int(x) explicitly converts variable x to integer type.

The value of the expressions 4/(3*(2 - 1)) and 4/3*(2 - 1) is the same.

Reason — Parentheses has first precedence then multiplication then division has precedence.

4/(3*(2-1)) = 4/(3*1) = 4/3 = 1.33333

4/3*(2-1) = 4/3*1 = 4/3 = 1.33333

The value of the expressions 4/(3*(4 - 2)) and 4/3*(4 - 2) is the same.

4/(3*(4-2)) = 4/(3*2) = 4/6 = 0.6666

4/3*(4-2) = 4/3*2 = 1.3333*2 = 2.6666

The expression 2**2**3 is evaluated as: (2**2)**3.

Reason — The expression 2**2**3 is evaluated as: 2**(2**3) because exponentiation operates from right to left (i.e., it is right associative).

A string can be surrounded by three sets of single quotation marks or by three sets of double quotation marks.

Reason — A string literal is a sequence of characters surrounded by single or double or triple double quotes or triple single quotes.

Variables can be assigned only once.

Reason — Python supports dynamic typing i.e., a variable can hold values of different types at different times.

In Python, a variable is a placeholder for data.

Reason — Variables represent labelled storage locations, whose values can be manipulated during program run.

In Python, only if statement has else clause.

Reason — Loops in Python can have else clause too.

Python loops can also have else clause.

Reason — Loops in Python can have else clause.

In a nested loop, a break statement terminates all the nested loops in one go.

Reason — In nested loops, a break statement will terminate the very loop it appears in.

Assertions and Reasons

Assertion. Assigning a new value to an int variable creates a new variable internally.

Reason. The int type is immutable data type of Python.

Both Assertion and Reason are true and Reason is the correct explanation of Assertion.

Explanation In python, literal values have fixed memory locations and variable names reference them as values. This means that, although we can change the value of an integer variable, the process involves creating a new integer object with the updated value. Literal values, such as 10, have fixed memory locations, and variables act as references to these values. When we assign a new value to an integer variable, we are essentially creating a new object, and the variable now points to this new object. Hence, both Assertion and Reason are true and Reason is the correct explanation of Assertion.

Assertion. """A Sample Python String""" is a valid Python String.

Reason. Triple Quotation marks are not valid in Python.

Assertion is true but Reason is false.

Explanation A string literal is a sequence of characters surrounded by single or double or triple single quotes or triple double quotes.

Assertion. If and For are legal statements in Python.

Reason. Python is case sensitive and its basic selection and looping statements are in lower case.

Assertion is false but Reason is true.

Explanation if is conditional statement and for is loop statement. Python is case sensitive and its selection and looping statements are in lower case.

Assertion. if and for are legal statements in Python.

Assertion. The break statement can be used with all selection and iteration statements.

Reason. Using break with an if statement is of no use unless the if statement is part of a looping construct.

Both Assertion and Reason are false.

Explanation In python, the break statement can be used with iteration statements only. Using break with conditional statements will result in syntax error — SyntaxError: 'break' outside loop

Reason. Using break with an if statement will give no error.

Type A: Short Answer Questions/Conceptual Questions

What are tokens in Python? How many types of tokens are allowed in Python? Exemplify your answer.

The smallest individual unit in a program is known as a Token. Python has following tokens:

  • Keywords — Examples are import, for, in, while, etc.
  • Identifiers — Examples are MyFile, _DS, DATE_9_7_77, etc.
  • Literals — Examples are "abc", 5, 28.5, etc.
  • Operators — Examples are +, -, >, or, etc.
  • Punctuators — ' " # () etc.

How are keywords different from identifiers?

Keywords are reserved words carrying special meaning and purpose to the language compiler/interpreter. For example, if, elif, etc. are keywords. Identifiers are user defined names for different parts of the program like variables, objects, classes, functions, etc. Identifiers are not reserved. They can have letters, digits and underscore. They must begin with either a letter or underscore. For example, _chk, chess, trail, etc.

What are literals in Python? How many types of literals are allowed in Python?

Literals are data items that have a fixed value. The different types of literals allowed in Python are:

  • String literals
  • Numeric literals
  • Boolean literals
  • Special literal None
  • Literal collections

State True or False : "Variable declaration is implicit in Python."

Reason — In Python, variable declaration is implicit. This means that we don't need to explicitly declare the data type of a variable before using it. The type of a variable is determined dynamically at runtime based on the assigned value. For example:

Out of the following, find those identifiers, which cannot be used for naming Variables or Functions in a Python program:

  • Price*Qty ⇒ Contains special character *
  • class ⇒ It is a keyword
  • 4thCol ⇒ Begins with a digit

Find the invalid identifier from the following :

The invalid identifier are:

2ndName ⇒ Begins with a digit True ⇒ It is a keyword

Which of the following is an invalid datatype in Python ?

Reason — Real is not a standard built-in data type in Python.

Identify the valid arithmetic operator in Python from the following:

Reason — Let's go through each option and see if its valid arithmetic operator or not:

  • ? — The question mark is not a valid arithmetic operator in Python.
  • < — It is a relational operator.
  • ** — It is an arithmetic operator.
  • and — It is a logical operator.

How are floating constants represented in Python? Give examples to support your answer.

Floating constants are represented in Python in two forms — Fractional Form and Exponent form. Examples:

  • Fractional Form — 2.0, 17.5, -13.0, -0.00625
  • Exponent form — 152E05, 1.52E07, 0.152E08, -0.172E-3

How are string-literals represented and implemented in Python?

A string-literal is represented as a sequence of characters surrounded by quotes (single, double or triple quotes). String-literals in Python are implemented using Unicode.

What are operators ? What is their function? Give examples of some unary and binary operators.

Operators are tokens that trigger some computation/action when applied to variables and other objects in an expression. Unary plus (+), Unary minus (-), Bitwise complement (~), Logical negation (not) are a few examples of unary operators. Examples of binary operators are Addition (+), Subtraction (-), Multiplication (*), Division (/).

Which of the following are valid operators in Python:

The valid operators are:

** ⇒ Exponentiation operator is ⇒ Identity operator ^ ⇒ Bitwise XOR operator in ⇒ Membership operator

What is an expression and a statement?

An expression is any legal combination of symbols that represents a value. For example, 2.9, a + 5, (3 + 5) / 4. A statement is a programming instruction that does something i.e. some action takes place. For example: print("Hello") a = 15 b = a - 10

What all components can a Python program contain?

A Python program can contain various components like expressions, statements, comments, functions, blocks and indentation.

What are variables? How are they important for a program?

Variables are named labels whose values can be used and processed during program run. Variables are important for a program because they enable a program to process different sets of data.

Consider the given expression: not True and False or True

Which of the following will be correct output if the given expression is evaluated?

Reason — The 'not' operator has the highest precedence, followed by 'and', which has precedence over 'or', and the evaluation proceeds from left to right. not True and False or True = False and False or True = False or True = True

Describe the concepts of block and body. What is indentation and how is it related to block and body?

A block in Python, represents a group of statements executed as a single unit. Python uses indentation to create blocks of code. Statements at same indentation level are part of same block/suite and constitute the body of the block.

Question 18(a)

What are data types? How are they important?

Data types are used to identify the type of data a memory location can hold and the associated operations of handling it. The data that we deal with in our programs can be of many types like character, integer, real number, string, boolean, etc. hence programming languages including Python provide ways and facilities to handle all these different types of data through data types. The data types define the capabilities to handle a specific type of data such as memory space it allocates to hold a certain type of data and the range of values supported for a given data type, etc.

Question 18(b)

Write the names of any four data types available in Python.

The names of any four data types in Python are:

How many integer types are supported by Python? Name them.

Two integer types are supported by Python. They are:

  • Integers (signed)

What are immutable and mutable types? List immutable and mutable types of Python.

Mutable types are those whose values can be changed in place whereas Immutable types are those that can never change their value in place.

Mutable types in Python are:

  • Dictionaries

Immutable types in Python are:

  • Floating-Point numbers

Question 21

What is the difference between implicit type conversion and explicit type conversion?

Question 22

An immutable data type is one that cannot change after being created. Give three reasons to use immutable data.

Three reasons to use immutable data types are:

  • Immutable data types increase the efficiency of the program as they are quicker to access than mutable data types.
  • Immutable data types helps in efficient use of memory storage as different variables containing the same value can point to the same memory location. Immutability guarantees that contents of the memory location will not change.
  • Immutable data types are thread-safe so they make it easier to parallelize the program through multi-threading.

Question 23

What is entry controlled loop? Which loop is entry controlled loop in Python?

An entry-controlled loop checks the condition at the time of entry. Only if the condition is true, the program control enters the body of the loop. In Python, for and while loops are entry-controlled loops.

Question 24

Explain the use of the pass statement. Illustrate it with an example.

The pass statement of Python is a do nothing statement i.e. empty statement or null operation statement. It is useful in scenarios where syntax of the language requires the presence of a statement but the logic of the program does not. For example,

Question 25

Rewrite the adjacent code in python after removing all syntax error(s). Underline each correction done in the code.

The corrected code is shown below:

Explanation

Correction 1 — Variable should be on left side and literals should be on right side. Correction 2 — Semi-colon was missing in the for loop syntax. Correction 3 — if statement should be in lower case. Correction 4 — else statement should be in lower case. Correction 5 — Full stop should not be there at the end of print function.

Question 26

Below are seven segments of code, each with a part coloured. Indicate the data type of each coloured part by choosing the correct type of data from the following type.

(a) int (b) float (c) bool (d) str (e) function (f) list of int (g) list of str

(i) bool (ii) str (iii) list of int (iv) int (v) bool (vi) list of str (vii) str

Question 27

Write the output of the following Python code:

range(2,7,2) returns [2, 4, 6] as it defines a range of 2 to 6 with a step of 2. The loop iterates as below:

  • For i = 2 , it prints $$ .
  • For i = 4 , it prints $$$$ .
  • For i = 6 , it prints $$$$$$ .

Type B: Application Based Questions

Fill in the missing lines of code in the following code. The code reads in a limit amount and a list of prices and prints the largest price that is less than the limit. You can assume that all prices and the limit are positive numbers. When a price 0 is entered the program terminates and prints the largest price that is less than the limit.

Question 2a

Predict the output of the following code fragments:

Question 2b

Question 2c.

Inside while loop, the line x = x - 10 is decreasing x by 10 so after 5 iterations of while loop x will become 40. When x becomes 40, the condition if x < 50 becomes true so keepgoing is set to False due to which the while loop stops iterating.

Question 2d

This is an endless (infinite) loop that will keep printing 45 continuously.

As the loop control variable x is not updated inside the loop neither there is any break statement inside the loop so it becomes an infinite loop.

Question 2e

x will be assigned each of the values from the list one by one and that will get printed.

Question 2f

range(1,10) will generate a sequence like this [1, 2, 3, 4, 4, 5, 6, 7, 8, 9]. p will be assigned each of the values from this sequence one by one and that will get printed.

Question 2g

range(-500, 500, 100) generates a sequence of numbers from -500 to 400 with each subsequent number incrementing by 100. Each number of this sequence is assigned to z one by one and then z gets printed inside the for loop.

Question 2h

This code generates No Output.

The x-y * 2 in range(x-y * 2) is evaluated as below:

    x - y * 2 ⇒ 10 - 5 * 2 ⇒ 10 - 10 [∵ * has higher precedence than -] ⇒ 0

Thus range(x-y * 2) is equivalent to range(0) which returns an empty sequence — [ ].

Question 2i

Outer loop executes 10 times. For each iteration of outer loop, inner loop executes 5 times. Thus, the statement c += 1 is executed 10 * 5 = 50 times. c is incremented by 1 in each execution so final value of c becomes 50.

Question 2j

In this code, the for loop is nested inside the while loop. Outer while loop runs 3 times and prints % as per the elements in x in each iteration. For each iteration of while loop, the inner for loop executes 3 times printing * as per the elements in x.

Question 2k

The for loop extracts each letter of the string 'lamp' one by one and place it in variable x. Inside the loop, x is converted to uppercase and printed.

Question 2l

Inside the while loop, each letter of x and y is accessed one by one and printed.

Question 2m

x.split(", ") breaks up string x into a list of strings so y becomes ['apple', 'pear', 'peach']. The for loop iterates over this list and prints each string one by one.

Question 2n

x.split(', ') breaks up string x into a list of strings so y becomes ['apple', 'pear', 'peach', 'grapefruit']. The for loop iterates over this list. apple and grapefruit are less than m (since a and g comes before m) so they are converted to lowercase and printed whereas pear and peach are converted to uppercase and printed.

Which of the following is the correct output for the execution of the following Python statement ?

According to operator precedence, exponentiation(**) will come first then division then addition.

5 + 3 ** 2 / 2 = 5 + 9 / 2 = 5 + 4.5 = 9.5

Question 4(i)

How many times will the following for loop execute and what's the output?

The loops execute 0 times and the code produces no output. range(-1, 7, -2) returns an empty sequence as there are no numbers that start at -1 and go till 6 decrementing by -2. Due to empty sequence, the loops don't execute.

Question 4(ii)

Loop executes for 5 times.

range(1,3,1) returns [1, 2]. For first iteration of outer loop j is in range [0, 1] so inner loop executes twice. For second iteration of outer loop j is in range [0, 1, 2] so inner loop executes 3 times. This makes the total number of loop executions as 2 + 3 = 5.

Find and write the output of the following python code:

The for loop iterates over each name in the list and prints it. If the name does not begin with the letter T, Finished! is printed after the name. If the name begins with T, break statement is executed that terminates the loop. Outside the loop, Got it! gets printed.

Is the loop in the code below infinite? How do you know (for sure) before you run it?

The loop is not infinite. To know this without running it we can analyze how n is changed inside the loop in the following way:

n = 2 * n - m

Substituting value of m from m = n - 1,

    n = 2 * n - (n - 1) ⇒ n = 2 * n - n + 1 ⇒ n = 2n - n + 1 ⇒ n = n + 1

Therefore, inside the loop n is incremented by 1 in each iteration. Loop condition is n < 10 and initial value of n is 5. So after 5 iterations, n will become 10 and the loop will terminate.

Type C: Programming Practice/Knowledge based Questions

Write a program to print one of the words negative, zero, or positive, according to whether variable x is less than zero, zero, or greater than zero, respectively.

Write a program that returns True if the input number is an even number, False otherwise.

Write a Python program that calculates and prints the number of seconds in a year.

Write a Python program that accepts two integers from the user and prints a message saying if first number is divisible by second number or if it is not.

Write a program that asks the user the day number in a year in the range 2 to 365 and asks the first day of the year — Sunday or Monday or Tuesday etc. Then the program should display the day on the day-number that has been input.

One foot equals 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.

Write a program that reads an integer N from the keyboard computes and displays the sum of the numbers from N to (2 * N) if N is nonnegative. If N is a negative number, then it's the sum of the numbers from (2 * N) to N. The starting and ending points are included in the sum.

Write a program that reads a date as an integer in the format MMDDYYYY. The program will call a function that prints print out the date in the format <Month Name> <day>, <year>.

Sample run :

Write a program that prints a table on two columns — table that helps converting miles into kilometers.

Write another program printing a table with two columns that helps convert pounds in kilograms.

Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between the two times.

A sample run is being given below :

MyCSTutorial- The path to Success in Exam

THE PATH TO SUCCESS IN EXAM...

Python Revision Tour I : Basics of Python – Notes

Class 12 – computer science : python revision tour – i, [a] – basics of python.

Topics are :

  • A : Basics of Pythons
  • B : Decision Making Statements
  • C : Loop and Jump Statements

INTRODUCTION

A python is an object-oriented, interpreted, high-level language and a very powerful programming language.

Developed by Guido Van Rossum  in 1991.

INSTALLATION

Download it from www.python.org  and install your computer by clicking on the installation file.

WORKING IN PYTHON 

In two modes  – (i) Interactive Mode and  (ii) Script Mode.

TOKENS IN PYTHON

The smallest individual unit in a program is called a token.

TYPES OF TOKEN

(i) Keyword  (ii) Identifiers   (iii) Literals  (iv) Operators  & (v) Punctuators

The word has a special meaning in a programming language.  If, else, while, for, or etc 

How to find the list of keywords in Python?

python_keyword_list

Identifiers

Names that are given to different parts of programs. Variable, Function, Class, etc.

Data items that have a fixed value.  Several types of literal in Python.

(a) String  (b) Numeric (c) Boolean (d) None

Triggers some computation or action when applied to the variables. +, -, / .

Punctuators

Symbols that are used  to organize sentence, structures and expressions. ‘  “ #  \ ( ) { } @ , : ; ` =, etc.

STRUCTURE  OF PYTHON PROGRAM

# This is a single line  comment # Function def thanks( name ):   print(“Thanks Mr/Ms. “, name , “for watching Anjeev Singh academy”) #Main Program a  =  20  # variable declaration and intialization b  =  30  c  =  a  +    b  # expression print (“Sum of “, a”, “and”, b, “is”, c )  if c > 40 :  # start of if block , showing by :   print(“You are eligible for lucky draw”) else:   print(“Sorry, Better Luck next time….”)

VARIABLES AND ASSIGNMENTS

A Variable is a named memory location, used for storing and manipulating values.

Example : Name = “Rashmi” , Age   = 18

python revision tour class 12 pdf

DYNAMIC TYPING

A variable pointing to a value of a certain type can be made to point to a value/object of a different type. This is called Dynamic Typing. For example:

N = “Rashmi”

N   = 18

python revision tour class 12 pdf

MULTIPLE ASSIGNMENTS

Assigning same value to multiple variables. E.g.  a = b = c = 10

Assigning  multiple values to multiple variables. E.g.  a , b , c  = 10, 20, 30

In python 3.x , input( ) is a built-in function, which allows user to input a value.

in_varibale  = input( <prompt message> )

Note : input( ) function always return  a value of String type.

int ( ) :- To convert a value in integer. => x = int (input(“A number plz”)).

float() :- To convert a value in float. => f = float (input(“a number plz:”)).

bool( ) :- To convert a value in Boolean. => b = bool (input(“Boolean value plz:”)) .

PRINT / OUTPUT

In python 3.x, print( ) is a built-in function, which allows the user to send output to a standard output device, i.e. monitor.

print( object , [ sep = ‘ ‘  or <separator string>, end = ‘\n’ or <end-string>] )

print (“Hello”) print (“Your marks is”, 20) print (“Welcome”, “You”, “All”, sep = ‘===‘) print( “Mobile”, end=‘ ‘) print (“9898989898”)

Data types are means to identify the type of data and the set of valid operations for it.

There are the following built-in core data types:-

python revision tour class 12 pdf

Numbers Data Types

Integers – Two types of integers in Python

  • a) Integer (signed) – number having only integer, either positive or negative
  • b) Booleans – represent truth values False and True. Boolean values False and True behave like values 0 and 1, respectively.

Floating Point Numbers

Is used to store numbers with a fraction part. They can be represented in scientific notation. Also called real numbers.

Example :  x = 25.036

     y = 4.95e3  => 495.00  => 4.95 x 10^3

Complex Numbers

Python allows to store the complex number.  Complex numbers are pairs of real and imaginary numbers. They can store in the form of ‘a+bj .  Both real and imag are internally represented as float value.

Example :   t = 2 + 3j

    t.real => gives the real part

    t.imag => gives the imaginary part as a float.

Sequence Data Types

Sequence Data Types is an ordered collection of items, indexed by integers (both +ve or –ve). Three types of sequence are – 

The string is a combination of letters, numbers, and special symbols.  In Python 3.x string is a sequence of Pure Unicode characters. Unicode is a system, designed to represent every character from every language.

Example : – “abc”, “12536”, “&*)()^%$”, “abcd12365&^%#’

A string is a sequence of characters and each character can be individually accessed using its index position i.e. forward (0,1, 2, …) and backward (-1, -2, -3, .. …)

The list is a set of comma-separated values of any datatype inside the square brackets. [  ]

Example =>  [1, 2 , 3 , 4, 5]  

    [1.5, 2.5, 4.5, 9.8] 

    [‘x’,  ‘y’, ‘z’]

    [‘anjeev’, 25,  4589.36, True]

The list can also be accessed through the index position i.e. forward and backward.

Related Posts

society law ethics

Society, Law, and Ethics: Societal Impacts – Notes

Interface python with mysql – notes, sql functions , grouping records, joins in sql – notes, simple queries in sql – notes, table creating and data manipulation commands – notes, relational databases – notes, network security aspects – notes, data communication – notes, leave a comment cancel reply.

You must be logged in to post a comment.

You cannot copy content of this page

python revision tour class 12 pdf

Class XII - Computer Science with Python

Thursday, may 21, 2020, class xii - cs(python) - ch 1. python revision tour - i, class xii - (cbse) chapter wise notes for computer science with python (new).

CH. 1. Python Revision Tour - I  -  PPT   -   PDF

CH 1. Worksheet 1 -  PDF

Ch 1 . Python Revision Tour - I

No comments:

Post a comment.

CBSE Skill Education

Python Revision Tour 1 Class 12 Notes

Teachers and Examiners ( CBSESkillEduction ) collaborated to create the Python Revision Tour 1 Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.

Token in Python

The smallest unit in a Python programme is called a token. In python all the instructions and statements in a program are built with tokens. Different type of tokens in python are keywords, identifier, Literals/values, operators and punctuators –

Words with a particular importance or meaning in a programming language are known as keywords. They are utilised for their unique qualities. There are 33 keywords in Python True, False, class, break, continue, and, as, try, while, for, or, not, if, elif, print, etc.

Identifiers

The names assigned to any variable, function, class, list, method, etc. for their identification are known as identifiers. Python has certain guidelines for naming identifiers and is a case-sensitive language. To name an identifier, follow these guidelines: –

  • Code in python is case – sensitive
  • Always identifier starts with capital letter(A – Z), small letter (a – z) or an underscore( _ ).
  • Digits are not allowed to define in first character but you can use between.
  • No whitespace or special characters are allowed.
  • No keyword is allowed to define identifier.

Literals or Values

In Python, literals are the raw data that is assigned to variables or constants during programming. There are five different types of literals string literals, numeric literals, Boolean literals and special literals none.

a) String literals

The string literals in Python are represented by text enclosed in single, double, or triple quotations. Examples include “Computer Science,” ‘Computer Science’, ”’Computer Science”’ etc. Note – Triple quotes string is used to write multiple line. Example – n1 = ‘Computer Science’ n2 = “Computer Science” n3 = ”’Computer Science”’ print(n1) print(n2) print(n3)

b) Numeric Literals

Literals that have been use to storing numbers is known is Numeric Literals. There are basicaly three numerical literals –

  • Integer Literal
  • Float Literal
  • Complex Literal

Example num1 = 10 num2 = 15.5 num3 = -20 print(num1) print(num2) print(num3)

c) Boolean Literal

Boolean literals have only two values True of False. Example num = (4 == 4) print(num)

d) Special literals none

The special literal “None” in Python used to signify no values, the absence of values, or nothingness. Example str = None print(str)

In Python, operators are specialized symbols that perform arithmetic or logical operations. The operation in the variable are applied using operands.

The operators can be arithmetic operators(+, -, * /, %, **, //), bitwise operators (&, ^, |), shift operators (<<, >>), identity operators(is, is not), relational operators(>, <, >=, <=, ==, !=), logical operators (and, or), assignment operator ( = ), membership operators (in, not in), arithmetic-assignment operators (/=, +=, -=, %=, **=, //=).

Punctuators

The structures, statements, and expressions in Python are organized using these symbols known as punctuators. Several punctuators are in python [ ] { } ( ) @ -= += *= //= **== = , etc.

Barebones of a python program

a) Expressions – An expression is a set of operators and operands that together produce a unique value when interpreted.

b) Statements – Which are programming instructions or pieces of code that a Python interpreter can carry out.

c) Comments – Python comments start with the hash symbol # and continue to the end of the line. Comments can be single line comments and multi-line comments.

d) Functions – A function is a block of code that only executes when called. You can supply parameters—data—to a function. As a result, a function may return data.

e) Block or suit – In Python, a set of discrete statements that together form a single code block are referred to as suites. All statements inside a block or suite are indented at the same level.

Variables and Assignments

A symbolic name that serves as a reference or pointer to an object is called a variable in Python. You can use the variable name to refer to an object once it has been assigned to it. However, the object itself still holds the data. Example name = “Python”

Dynamic Type vs Static Type

The term “dynamic typing” refers to a variable’s type only being established during runtime. Whereas the statically type done at compile time in a python. Statically type of a variable cannot be change.

Multiple Assignments

Values are assigned by Python from right to left. You can assign numerous variables simultaneously in a single line of code using multiple assignment. a) Assigning same value to multiple variables n3 = n2 = n1 = 20 b) Assigning multiple values to multiple variables n1, n2, n3 = 10, 20, 30

Simple input and output

Input .

Python automatically treats every input as a string input. To convert it to any other data type, we must explicitly convert the input. For this, we must utilize the int() and float() methods to convert the input to an int or a float, respectively. example name = input(‘What is your name’) age = int(input(‘What is your age’)

The print() method in Python allows users to display output on the screen. print statement automatically converts the items to strings. example num = 10 print(“Number is “) print(num) # auto converted to string print(34) # auto converted to string

The classification or categorizing of data elements is known as data types. It represents the type of value that specifies the operations that can be carried out on a given set of data. In Python programming, everything is an object, hence variables and data types are both instances or objects.

Python has following data types by default.

Data types for Numbers

a) Integer – The integers represent by “int”. It contains positive or negative values. b) Boolean – The boolean type store on True or False, behave like the value 0 and 1. c) Floating – It is a real number with specified with decimal point. d) Complex – Complex class is a representation of a complex number (real part) + (imaginary part)j. For example – 2+3j.

Data types for String

Strings in Python are collections of Unicode characters. A single, double, or triple quote are used to store string. There is no character data type in Python. Example name = ‘Computer Science’ name1 = “Computer Science’ name2 = ”’Computer Science”’

Lists are similar to arrays, it is a collections of data in an ordered way. list’s items don’t have to be of the same type in python. Example my_list = [1, 2, 3] my_list1 = [“Computer”, “Science”, “Python”] my_list2 = [“Computer Science”, 99]

Tuple is similar to lists, It is also an ordered collection of python. The only difference between tuple and list is that tuples can’t be modified after it is created, So, that’s why it is known as immutable. Example my_tuple = (1, 2, 3) my_tuple1 = (“Computer”, “Science”, “Python”) my_tuple2 = (“Computer Science”, 99)

Dictionaries

In Python, a dictionary is an unordered collection of data values that can be used to store data values like a map. This dictionary can hold only single value as an element, Dictionary holds key:value pair. Example my_dict = (1: ‘Computer’, 2: ‘Mathematics’, 3: ‘Biology’) my_dict = (‘Computer’: 1, ‘Mathematics’: 2, ‘Biology’: 3)

Mutable and Immutable Types

In Python, there are two different types of objects: mutable and immutable. It is possible to change mutable data types after they have been formed, whereas immutable objects cannot be altered once they have been created.

Mutable types

The mutable types are those whose values can be changed in place. Only three types are mutable in python lists, dictionaries and sets.

Immutable types

The immutable types are those that can never change their value in place. In Python, the following types are immutable in python integers, floating point numbers, Booleans, strings, tuples.

Expressions

In Python, an expression is made up of both operators and operands. example of expressions in python are num = num + 3 0, num = num + 40. Operators in Python are specialised symbols that indicate that a particular type of computation should be carried out. Operands are the values that an operator manipulates. An expression is a collection of operators and operands, such as num = num + 3 0.

Type Casting (Explicit Type Conversion)

Type casting, often known as explicit type conversion, Users change the data type of an object to the required data type via explicit type conversion. To achieve explicit type conversion, we use predefined functions like int(), float(), str(), etc.

Math Library Functions

The Python standard library includes a built-in module called math that offers common mathematical functions.

  • math.ceil() – The ceil() function return the smallest integer.
  • math.sqrt() – The sqrt() function returns the square root of the value.
  • math.exp() – The exp() function returns the natural logarithm reised to the power.
  • math.fabs() – The fabs() function returns the absolute value.
  • math.floor() – The floor() function returns round a number down to the nearest intger.
  • math.log() – The log() function is used to calculate the natural logarithmic value.
  • math.pow() – The pow() function returns base raised to exp power.
  • math.sin() – The sin() function returns sine of a number.
  • math.cos() – The cos() function return the cosine of the value.
  • math.tan() – The tan() function return the tangent of the value.
  • math.degrees() – The degrees() converts angle of value from degrees to radians.

Statement Flow Control

Control flow refers to the sequence in which a program’s code is executed. Conditions, loops, and function calls all play a role in how a Python programme is controlled. Python has three types of control structures – a) Sequential – By default mode b) Selection – Used in decision making like if, swithc etc. c) Repetition – It is used in looping or repeating a code multiple times

Compound Statement

Compound statements include other statements (or sets of statements), and they modify or direct how those other statements are executed. Compound statements often take up numerous lines, however in some cases, a complete compound statement can fit on a single line. Example <compound statement header> : <indented body containing multiple simple and/ or compound statement>

The IF & IF-ELSE conditionals

When using the if statement in Python, a Boolean expression is evaluated to determine whether it is true or false. If the condition is true, the statement inside the if block is executed. If the condition is false, the statement inside the else block is only executed if you have written the else block; otherwise, nothing happens. Syntax of IF condition – if <conditional expression> :      statement      [statement]

Syntax of IF-ELSE condition – if <conditional expression> :      statement      [statement] else :      statement      [statement]

Nested IF statement

One IF function contains one test, with TRUE or FALSE as the two possible results. You can test numerous criteria and expand the number of outcomes by using nested IF functions, which are one IF function inside of another. Syntax of Nested IF statement if condition :      if condition :           Statement      else :           Statement

Looping Statement

In Python, looping statements are used to run a block of statements or code continuously for as many times as the user specifies. Python offers us two different forms of loops for loop and while loop.

The For loop

Python’s for loop is made to go over each element of any sequence, such a list or a string, one by one. Syntax of FOR loop – for <variable> in <sequence> :      statements_to_repeat

The range() based for loop

The range() function allows us to cycle across a set of code a predetermined number of times. The range() function returns a series of numbers and, by default, starts at 0 and increments by 1 before stopping at a predetermined value. Syntax – range(stop) range(start, stop) range(start, stop, step)

The While loop

A while loop is a conditional loop that will repeat the instructions within itself as long as a conditional remain true. Syntax – while <logical expression> : loop-body

JUMP Statemement – break and condinue

Python offers two jump statement – break and continue – to be used within loops to jump out of loop-iterations.

The break Statement

A break statement terminates the very loop it lies within. Execution resumes at the statement immediately following the body of the terminated statement. Syntax – break

Example – a = b = c = 0 for i in range(1, 11) :      a = int(input(“Enter number 1 :”))      b = int(input(“Enter number 2 :))      if b == 0 :           print(“Division by zero error! Aborting”)           break      else           c=a/b           print(“Quotient = “, c) print(“program over!”)

The continue statement

Unlike break statement, the continue statement forces the next iteration of the loop to take place, skipping any code in between. Syntax – continue

Loop else statement

Python supports combining the else keyword with both the for and while loops. After the body of the loop, the else block is displayed. After each iteration, the statements in the else block will be carried out. Only when the else block has been run does the programme break from the loop. Syntax – for <variable> in <sequence> :      statement1      statement2 else :      statement(s)

while <test condition> :      statement1      statement2 else :      statement(s)

Nested Loops

A loop may contain another loop in its body. This form of a loop is called nested loop. But in a nested loop, the inner loop must terminate before the outer loop. The following is an example of a nested loop : for i in range(1,6) :      for j in range(1, i) :           print(“*”, end =’ ‘)      print()

python revision tour class 12 pdf

+918076665624

Learnpython4cbse, inspiring success, click here for, vide o tutorial @ youtube channel supernova, there’s nothing here....

We can’t find the page you’re looking for. Check the URL, or head back home.

python revision tour class 12 pdf

StudyTalkies.com website logo

[Type B] Python Revision Tour-1 – Chapter 1

Sumita Arora Class 12 Python Solutions is what you might have searched for. This is Unit 1 namely Python Revision tour for class 12. Follow along for computer science with python class 12 sumita arora solutions (PDF). You can print the page as PDF for future reference. Type B Question Solutions are covered.

1. Fill in the missing lines of code in the following code. The code reads in a limit amount a prices and prints the largest price that is less than the limit. You can assume that all prices and the limit are positive numbers. When a price 0 is entered the program terminates and prints the largest price that is less than the limit.

  • 2. Predict the outputs of the following programs:-
  • 3. Find and write the output of the following python code:
  • 4. How many times will the following for loop execute and what’s the output?
  • 5. Is the loop in the code below infinite? How do you know (for sure) before you run it?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

CBSE Python

CS-IT-IP-AI and Data Science Notes, QNA for Class 9 to 12

150+ MCQ Revision Tour of python class 12

Unit -1: computational thinking and programming-2, topic: revision of python topics covered in class xi.

1. Which of the following is a valid identifier:

c) Same-type

Show Answer

2. Which of the following is a relational operator:

3. Which of the following is a logical operator:

4. Identify the membership operator from the following:

c) both i & ii

5. Which one is a arithmetic operator:

d) Only ii 

6. What will be the correct output of the statement : >>>4//3.0

d) None of the above

7. What will be the correct output of the statement : >>> 4+2**2*10

8. Give the output of the following code:

>>> a,b=4,2

>>> a+b**2*10

9. Give the output of the following code:

>>> a,b = 4,2.5

>>> a-b//2**2

10. Give the output of the following code:

>>>a,b,c=1,2,3

>>> a//b**c+a-c*a

11. If a=1,b=2 and c= 3 then which statement will give the output as : 2.0 from the following:

a) >>>a%b%c+1

b) >>>a%b%c+1.0  

c) >>>a%b%c

b) >>>a%b%c+1.0 

12. Which statement will give the output as : True from the following :

a) >>>not -5

b) >>>not 5

c) >>>not 0 

d) >>>not(5-1)

13. Give the output of the following code:

>>>7*(8/(5//2))

14. Give the output of the following code:

>>>import math

>>> math.ceil(1.03)+math.floor(1.03)

15.What will be the output of the following code:

>>>math.fabs(-5.03)

16.Single line comments in python begin with……………….. symbol.

17.Which of the following are the fundamental building block of a python program.

a) Identifier 

b) Constant

c) Punctuators

18.The input() function always returns a value of ……………..type.

19.……….. function is used to determine the data type of a variable.

a) type( ) 

c) print( )

20.The smallest individual unit in a program is known as a……………

c) punctuator

d) identifier

FLOW OF EXECUTION

#Decision making statements in python Statement

21. Which of the following is not a decision making statement

a) if..else statement

b) for statement 

c) if-elif statement

d) if statement

22. …………loop is the best choice when the number of iterations are known.

b) do-while

d) None of these

23. How many times will the following code be executed.

while a>0:

print(“Bye”)

c) Infinite

24. What abandons the current iteration of the loop

a) continue

c) infinite

25. Find the output of the following python program

for i in range(1,15,4):

print(i, end=’,’)

c) 1,5,10,14

d) 1,5,9,13 

26. …………loop is the best when the number of iterations are not known.

27.In the nested loop ……………..loop must be terminated before the outer loop.

b) enclosing

28. …………..statement is an empty statement in python.

c) continue

29. How many times will the following code be executed

for i in range(1,15,5):

print(i,end=’,’)

d) infinite

30. Symbol used to end the if statement:

a) Semicolon(;)

b) Hyphen(-)

c) Underscore( _ )

d) colon(:)

String Methods and Built-in functions:

31. Which of the following is not a python legal string operation.

a) ‘abc’+’aba’

c) ‘abc’+3 

d) ‘abc’.lower()

32. Which of the following is not a valid string operation.

b) concatenation

c) Repetition

33. Which of the following is a mutable type.

34. What will be the output of the following code

str1=”I love Python”

strlen=len(str1)+5

print(strlen)

35. Which method removes all the leading whitespaces from the left of the string.

b) remove()

c) lstrip()

d) rstrip()

36. It returns True if the string contains only whitespace characters, otherwise returns False.

a) isspace()

c) islower()

d) isupper()

37. It converts uppercase letter to lowercase and vice versa of the given string.

a) lstrip()

b) swapcase()

c) istitle()

38.What will be the output of the following code.

Str=’Hello World! Hello Hello’

Str.count(‘Hello’,12,25)

39.What will be the output of the following code.

Str=”123456”

print(Str.isdigit())

40.What will be the output of the following code.

Str=”python 38”

print(Str.isalnum())

41.What will be the output of the following code.

Str=”pyThOn”

print(Str.swapcase())

42.What will be the output of the following code.

Str=”Computers”

print(Str.rstrip(“rs”))

a) Computer

b) Computers

c) Compute 

43.What will be the output of the following code.

Str=”This is Meera\’ pen”

44.How many times is the word ‘Python’ printed in the following statement.

s = ”I love Python”

for ch in s[3:8]:

print(‘Python’)

a) 11 times

d) 5 times 

45.Which of the following is the correct syntax of string slicing:

a) str_name[start:end] 

b) str_name[start:step]

c) str_name[step:end]

d) str_name[step:start]

46.What will be the output of the following code?

A=”Virtual Reality”

print(A.replace(‘Virtual’,’Augmented’))

a) Virtual Augmented

b) Reality Augmented

c) Augmented Virtual

d) Augmented Reality 

47.What will be the output of the following code?

print(“ComputerScience”.split(“er”,2))

a) [“Computer”,”Science”]

b) [“Comput”,”Science”] 

c) [“Comput”,”erScience”]

d) [“Comput”,”er”,”Science”]

48.Following set of commands are executed in shell, what will be the output?

>>>str=”hello”

>>>str[:2]

49.………..function will always return tuple of 3 elements.

c) partition()

50.What is the correct python code to display the last four characters of “Digital India”

a) str[-4:] 

c) str[*str]

d) str[/4:]

51. Given the list L=[11,22,33,44,55], write the output of print(L[: :-1]).

a) [1,2,3,4,5]

b) [22,33,44,55]

c) [55,44,33,22,11] 

d) Error in code

52. Which of the following can add an element at any index in the list?

a) insert( ) 

b) append( )

c) extend()

d) all of these

53. Which of the following function will return a list containing all the words of the given string?

54.Which of the following statements are True.

i) [1,2,3,4]>[4,5,6]

ii) [1,2,3,4]<[1,5,2,3]

iii) [1,2,3,4]>[1,2,0,3]

iv) [1,2,3,4]<[1,2,3,2]

b) i,iii,iv

c) i,ii,iii

55. If l1=[20,30] l2=[20,30] l3=[‘20’,’30’] l4=[20.0,30.0] then which of the following statements will not return ‘False’:

i) >>>l1==l2

ii) >>>l4>l1

iii) >>>l1>l2

iv) >>> l2==l2

b) i,ii,iii

c) i,iii,iv

56.>>>l1=[10,20,30,40,50]

>>>l2=l1[1:4]

What will be the elements of list l2:

a) [10,30,50]

b) [20,30,40,50]

c) [10,20,30]

d) [20,30,40] 

57.>>>l=[‘red’,’blue’]

>>>l = l + ‘yellow’

What will be the elements of list l:

a) [‘red’,’blue’,’yellow’]

b) [‘red’,’yellow’]

c) [‘red’,’blue’,’yellow’]

58.What will be the output of the following code:

>>>l=[1,2,3,4]

>>>m=[5,6,7,8]

>>>n=m+l

>>>print(n)

a) [1,2,3,5,6,7,8]

b) [1,2,3,4,5,6,7,8] 

c) [1,2,3,4][5,6,7,8]

59.What will be the output of the following code:

>>>m=l*2

>>>n=m*2

a) [1,2,3,4,1,2,3,4,1,2,3,4]

b) [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4] 

c) [1,2,3,4][4,5,6,7]

d) [1,2,3,4]

60.Match the columns: if

>>l=list(‘computer’)

 a) 1-b,2-d,3-a,4-c 

b) 1-c,2-b,3-a,4-d

c) 1-b,2-d,3-c,4-a

d) 1-d,2-a,3-c,4-b

61. If a list is created as

>>>l=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]] then what will be the output of the following statements:

>>>l[4][1]

b) ‘green’ 

d) ‘orange’

62.>>>l[8][0][2]

63.>>>l[-1]

a) [‘apple’,’green’]

b) [‘red’,’orange’]

c) [‘red’ ] 

d) [’orange’]

64.>>>len(l)

65.What will be the output of the following code:

>>>l1=[1,2,3]

>>>l1.append([5,6])

>>>l1

a) [1,2,3,5,6]

b) [1,2,3,[5,6]]

d) [1,2,3,[5,6]] 

66.What will be the output of the following code:

>>>l2=[5,6]

>>>l1.extend(l2)

a) [5,6,1,2,3]

b) [1,2,3,5,6] 

d) [1,2,3,6]

67. What will be the output of the following code:

>>>l1.insert(2,25)

a) [1,2,3,25]

b) [1,25,2,3]

c) [1,2,25,3] 

d) [25,1,2,3,6]

68. >>>l1=[10,20,30,40,50,60,10,20,10]

>>>l1.count(‘10’)

69.Which operators can be used with list?

c) both (i)&(ii) 

d) Arithmetic operator only

70.Which of the following function will return the first occurrence of the specified element in a list.

d) sorted()

MCQ Tuples and Dictionary:

71. Which of the statement(s) is/are correct.

a) Python dictionary is an ordered collection of items.

b) Python dictionary is a mapping of unique keys to values

c) Dictionary is mutable.

d) All of these. 

72. ………function is used to convert a sequence data type into tuple.

73. It tup=(20,30,40,50), which of the following is incorrect

a) print(tup[3])

b) tup[2]=55

c) print(max(tup))

d) print(len(tup))

74. Consider two tuples given below:

>>>tup1=(1,2,4,3)

>>>tup2=(1,2,3,4)

What will the following statement print(tup1<tup2)

75. Which function returns the number of elements in the tuple

d) count( )

76. Which function is used to return a value for the given key.

77.Keys of the dictionary must be

c) can be similar or unique

d) All of these

78. Which of the following is correct to insert a single element in a tuple .

79.Which of the following will delete key-value pair for key=’red’ form a dictionary D1

a) Delete D1(“red”)

b) del. D1(“red”)

c) del D1[“red”] 

80.Which function is used to remove all items form a particular dictionary.

a) clear( ) 

81.In dictionary the elements are accessed through

82.Which function will return key-value pairs of the dictionary

b) values( )

c) items( ) 

83.Elements in a tuple can be of ………….type.

a) Dissimilar

c) both i & ii 

84.To create a dictionary , key-value pairs are separated by…………….

85.Which of the following statements are not correct:

i) An element in a dictionary is a combination of key-value pair

ii) A tuple is a mutable data type

iii) We can repeat a key in dictionary

iv) clear( ) function is used to deleted the dictionary.

a) i,ii,iii

b) ii,iii,iv 

c) ii,iii,i

d) i,ii,iii,iv

86.Which of the following statements are correct:

i) Lists can be used as keys in a dictionary

ii) A tuple cannot store list as an element

iii) We can use extend() function with tuple.

iv) We cannot delete a dictionary once created.

b) ii,iii,iv

87.Like lists, dictionaries are……………..which mean they can be changed.

a) Mutable 

b) immutable

c) variable

88.To create an empty dictionary , we use

d) d= < >

89.To create dictionary with no items , we use

b) dict( ) 

90.What will be the output

>>>d1={‘rohit’:56,”Raina”:99}

>>>print(“Raina” in d1)

c) No output

91. Rahul has created the a tuple containing some numbers as

>>>t=(10,20,30,40)

now He want to add a new element 60 in the tuple, which statement he should use out of the given four.

a) >>>t+(60)

b) >>>t + 60

c)  >>>t + (60,) 

d) >>>t + (‘60’)

92. Rahul wants to delete all the elements from the tuple, which statement he should use

a) >>>del t

b) >>>t.clear()

c)  >>>t.remove()

d) >>>None of these

93.Rahul wants to display the last element of the tuple, which statement he should use

a) >>> t.display()

b) >>>t.pop()

c) >>>t[-1] 

d) >>>t.last()

94.Rahul wants to add a new tuple t1 to the tuple t, which statement he should use

a) >>>t+t1

b) >>>t.add(t1)

c) >>>t*t1

95. Rahul has issued a statement after that the tuple t is replace with empty tuple, identify the statement he had issued out of the following:

a) >>> del t

b) >>>t= tuple()

c) >>>t=Tuple()

d) >>>delete t

96. Rahul wants to count that how many times the number 10 has come:

a) >>>t.count(10) 

b) >>>t[10]

c) >>>count.t(10)

97. Rahul want to know that how many elements are there in the tuple t, which statement he should use out of the given four

a) >>>t.count()

b) >>>len(t) 

c) >>>count(t)

d) >>>t.sum()

98.>>>t=(1,2,3,4)

Write the statement should be used to print the first three elements 3 times

a) >>>print(t*3)

b) >>>t*3

c)  >>>t[:3]*3

d) >>>t+t

99. Match the output with the statement given in column A with Column B.

a) 1-b,2-c,3-d,4-a

b) 1-a,2-c,3-d,4-b

c) 1-c,2-d,3-a,4-a

d) 1-d,2-a,3-b,4-c

100. Write the output of the following code:

>>>d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}

>>>d1={‘name’:‘raj’)

>>>d1=d.copy()

>>>print(“d1 :”d1)

a) d1 : {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

b) d1 = {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

c) {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’}

d) (d1 : {‘name’: ‘rohan’, ‘dob’: ‘2002-03-11’, ‘Marks’: ’98’})

Related Post

Class 12 computer science board question paper 2024 with answer key, python function arguments and parameters notes class 12 (positional, keyword, default), class 12 computer science notes topic wise.

IMAGES

  1. Revision Notes

    python revision tour class 12 pdf

  2. Python Revision tour

    python revision tour class 12 pdf

  3. Python Revision tour

    python revision tour class 12 pdf

  4. Best Notes Python Revision Tour 1 Class12 with solved passed CBSE Ques

    python revision tour class 12 pdf

  5. Class 12 Python

    python revision tour class 12 pdf

  6. Revision tour of Python Class 12

    python revision tour class 12 pdf

VIDEO

  1. Day 38: Python Revision Tour 4

  2. M110 Python Revision 1

  3. PYTHON REVISION TOUR INTRO |PYTHON

  4. Python Class || Mutable Types || Immutable Types || Revision Tour ||class 12 #mutable #immutable

  5. Dictionaries in Python for Class 12 Boards

  6. MASTER Strategy for Board 2023-24

COMMENTS

  1. PDF Python Revision Tour

    y, y = 10, 20. In above code first it will assign 10 to y and again it assign 20 to y, so if you print the value of y it will print 20. Now guess the output of following code. x, x = 100,200 y,y = x + 100, x +200 print(x,y) In python we can take input from user using the built-in function input().

  2. Python Revision Tour Class 12 Notes

    How to execute or run python program. Open python IDLE. Click 'File' and select 'New' to open Script mode. Type source code and save it. Click on 'Run' menu and select 'Run Module'. Python Keywords. These are predefined words which a specific meaning to Python Interpreter. These are reserve keywords.

  3. Python Revision Tour Class 12 Notes

    Python Revision Tour Class 12 Notes Token in Python. The smallest unit in a Python programme is called a token. In python all the instructions and statements in a program are built with tokens. Different type of tokens in python are keywords, identifier, Literals/values, operators and punctuators - Keywords

  4. Python Revision Tour

    Get answers to all exercises of Chapter 1: Python Revision Tour Sumita Arora Computer Science with Python CBSE Class 12 book. Clear your computer doubts instantly & get more marks in computers exam easily. Master the concepts with our detailed explanations & solutions.

  5. Python Revision Tour I : Basics of Python

    Class 12 - Computer Science : Python Revision Tour - I [A] - Basics of Python Topics are : INTRODUCTION A python is an object-oriented, interpreted, high-level language and a very powerful programming language. Developed by Guido Van Rossum in 1991. INSTALLATION Download it from www.python.org and install your computer by clicking on the installation […]

  6. PDF REVISION TOUR I (CLASS XII)

    REVISION TOUR I (CLASS XII) 1. What is the output of the following? x = ['ab', 'cd'] for i in x: i.upper() print(x) a) ["ab", "cd"]. b) ["AB", "CD"].

  7. Revision Notes

    Revision Notes - Chapter 1 Python Revision Tour 1 - CBSE Computer Science Class 12 - Free download as PDF File (.pdf) or read online for free. Handwritten Revision Notes for CBSE Class 12 Computer Science, Chapter 1 - Python Revision Tour 1. According to recent syllabus.

  8. Python Revision Tour: Rapid Revision for Class 12 ...

    Python Revision Tour: Rapid Revision🔥 for Class 12 Computer Science (with Notes)Welcome to our channel dedicated to helping Class 12 Computer Science studen...

  9. Python Revision Tour 1

    Python Revision Tour 1 | Getting Started With Python Class 12 Computer Science with Python #01Class: 12thSubject: Computer ScienceChapter: Python Revision To...

  10. Python Revision Tour

    Check the Entire Playlist (Class 12 Python Programming)https://www.youtube.com/watch?v=MIuEsAvov0c&list=PLDA2q3s0-n17FPQjb4WGxQ2S3Kce0w2aXCheck the Entire Pl...

  11. CLASS XII

    Class XII - (CBSE) Chapter wise notes for Computer Science with Python (New) CH. 1. Python Revision Tour - I - PPT - PDF. CH 1. Worksheet 1 - PDF. Posted by Gubert L at 12:49 PM. Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest.

  12. Chapter 1: Python Revision Tour (Part -I)

    Get access to the latest Chapter 1: Python Revision Tour (Part -I) prepared with CBSE Class 12 course curated by Niharika Kushwah on Unacademy to prepare for the toughest competitive exam. ... Class 12 Computer Science With Python. 20 lessons • 3h 55m . 1. Chapter 4 : Class And Instance. 11:34mins. 2. Concept of Data Hiding With Python. 7 ...

  13. Python Revision Tour 1 Class 12 Notes

    Python Revision Tour 1 Class 12 Notes. Loop else statement. Python supports combining the else keyword with both the for and while loops. After the body of the loop, the else block is displayed. After each iteration, the statements in the else block will be carried out. Only when the else block has been run does the programme break from the loop.

  14. 2. Python Revision Tour

    Python Revision Tour - I. Python Revision Tour - II. Working with function. Using Python Libraries. Recursion. Data File Handling: Working with Text files. Data File Handling: Working with Binary files. Data File Handling: Working with CSV files. Data Structure: Searching and Sorting.

  15. Python Revision Tour-1 Type B Solutions

    This is Unit 1 namely Python Revision tour for class 12. Follow along for computer science with python class 12 sumita arora solutions (PDF). You can print the page as PDF for future reference. Type B Question Solutions are covered. Table of Contents. 1. Fill in the missing lines of code in the following code. The code reads in a limit amount a ...

  16. Revision Tour 1 Notes

    This video will help you to get class 12 chapter 1 revision tour 1 notes in pdf form. Also you will get lectures on python for class 12.Connect with Me: INST...

  17. Revision Notes

    Revision Notes - Chapter 2 Python Revision Tour 2 - CBSE Computer Science Class 12 - Free download as PDF File (.pdf) or read online for free. Handwritten Revision Notes for CBSE Class 12th Computer Science, Chapter 2 - Python Revision Tour 2. According to recent syllabus.

  18. Class-12 Ch-2 Python Revision Tour-II

    Class-12 Ch-2 Python Revision Tour-II - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. Strings

  19. Python revision tour i

    Python revision tour i. 1. Computer Science with Python Class: XII Unit I: Computational Thinking and Programming -2 Chapter 1: Review of Python basics I (Revision Tour Class XI) Mr. Vikram Singh Slathia PGT Computer Science. 2. Python • In class XI we have learned about Python. In this class we will learn Python with some new techniques.

  20. Lesson Plan

    Lesson Plan - XII - Chapter 1 - Python Revision Tour I - Free download as Word Doc (.doc), PDF File (.pdf), Text File (.txt) or read online for free. This lesson plan aims to revise major Python concepts like tokens, variables, and flow control statements that were taught in the previous class. The plan outlines pre-lesson activities like identifying tokens and labeling Python program structures.

  21. 150+ MCQ Revision Tour of python class 12 CBSE Python

    Topic: Revision of python topics covered in class XI. 1. Which of the following is a valid identifier: 2. Which of the following is a relational operator: 3. Which of the following is a logical operator: 4. Identify the membership operator from the following: