0% found this document useful (0 votes)
10 views

1. Python Revision Tour – I

SuperNova-LearnPython is a YouTube channel aimed at helping students learn Python and computer science concepts, covering topics like programming, data handling, and SQL. The channel provides resources such as video explanations, notes, and sample papers for classes 11 and 12. Additionally, the document outlines various Python programming fundamentals, including data types, control flow, and functions.

Uploaded by

ASHINI VIJAY
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
10 views

1. Python Revision Tour – I

SuperNova-LearnPython is a YouTube channel aimed at helping students learn Python and computer science concepts, covering topics like programming, data handling, and SQL. The channel provides resources such as video explanations, notes, and sample papers for classes 11 and 12. Additionally, the document outlines various Python programming fundamentals, including data types, control flow, and functions.

Uploaded by

ASHINI VIJAY
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
(} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs Revision Tow SuperNova-LearnPython, a YouTube channel dedicated to helping students to learn Python and computer science concepts. The channel covers various topics related to computer science, including Python programming, data file handling, computer networking, SQL and many more. If you're looking for video descriptions, notes, assignments, and previous years’ question papers related to Python and computer science for class 11 and 12, | recommend checking out the SuperNova-LearnPython channel on YouTube. You can find the channel here’. Happy learning! . Please like, Subscribe and share the Channel Link for Video Explanation of Revision Tour - 1: Video 1: hitps://voutu.be/eqDFuhGhoPg Video 2: https://voutu.be/QkP_XpedEow SuperNova-LearnPython customize chanel Manoge wear Home Videos Live Playlists Community For You One flehanding iss 120 sot et fle ‘One Shot Computer Networking with PYGs|esclss Class 1 IP Revision Assgnmen-7| Class 71 Manag fr las 12 ae Intrmates ra Page 1 of 20 Website: https:/ /www.leampythondchse.com/ About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs oreo Bess pera ome Picking erremeen nc ret ee eee Dictionary Preece ary erecta caret] ae Pee roe Cone Le ‘Scope of Variable ‘Working with Text File Page 2 of 20 Website: https:/ /www.leampythondchse.com/ ej AboutUs Learnpython4cbse PYTHON | ONLINE CLASSES Website: https://www.leampythondcbse.com/ Cees [@ Feedback (@) ( 8076065624 annel: ecto) acne SCOT Paci rude Beas Different DataStructure Relational Database Management System (SQL-commandsSyntaxwith Example )- ‘Terminology Used in DEMS and Types of ( Keys \ Degreeand Cardinality } ( DDLComimands: Create, Alter and Drop ‘SQL Operators y Sree Pret Switching Techniques: Cirenit, Message Wa eed ==s- >’ eed eR The Power of Preparat Page 3 of 20 ACK using») (Tmplementation of STACK using? aust Push (), Pop() and Peek ( ‘Operations DMLCommands: Insert Into, ‘Update, Delete the records ‘Grouping Records, Joinsin SQL: Use of Having and Group by elause_/ ( AsgregateFunctions: Count, + Sum; Stax0,MinOvand Avg Gay ee - oor Nard eee eee eens Roe in: Books and Questions Website: https:/ /www.leampythondchse.com/ (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs REVISION TO I Links for Video Explanation of Revision Tour - 1: Video 1: https://youtu.be/cqDFuhGhoPg Video 2: https://youtu.be/QkP_XpedEow Python was created by Guido Van Rossum in late '1980s' (Released in 1991) at National Research Institute in the Netherland. Python got its name from a BBC comedy series - “Monty Python's Flying Circus”. Python is based on two programming languages: (i) ABC language (ii) Modula 3 Some qualities of Python based on the programming fundamentals are given below: * Interactive Mode: Interactive mode, as the name suggests, allows us to work interactively. It executes the code by typing one command at a time in Python shell. + Script Mode: In script mode, we type Python program in a file and then execute the content of the file. + Indentation: Blocks of code are denoted by line indentation, which is rigidly enforced. + Comments: A hash sign (#) that is not inside a string literal begins a single line comment. We can use triple quoted string for giving multi-line comments. + Variables: A variable in Python is defined through assignment. There is no concept of declaring a variable Other than assignment. Value of variable can be manipulated during program run. Page 4 of 20 Website: https:/ /www.leampythondchse.com/ ea ee ae ene ced Reece Meee Nac Page 5 of 20 Website: Website: Ee ve Tee ec Dynamic Typing: In Python, while the value that a variable points to has a type, the variable itself has no strict type in its definition Static Typing: In static typing, a data type is attached with a variable when it is defined first and itis fixed. Multiple Assignment: Python allows you to assign a single value to several variables and multiple values to multiple variables simultaneously. For example: a=b=e=1 a,b, ¢ = 1, 2, “john” Token: The smallest individual unit in a program is known as a Token or a lexical unit. Identifiers: An identifier is a name used to identify a variable, function, class, module, or other object. An identifier starts with a letter A to Z or a to z or an underscore (_ ) followed by zero or more letters, underscores, and digits (0 to 9). Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language. Thus, Value and value are two different identifiers in Python. Words (Keywords): The following list shows the reserved words in Python v3.0 or later are eet oa ce err Ps else is eens SET io ry Poe te bg Teorey for a (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs ¥ These reserved words should not be used as constant or variable or any other identifier names. All the Python keywords contain lowercase letters only except False, None and True which have first letter capital. * Literal/Constant: Literals (Often referred to as constant value) are data items that have a fixed value. Python allows several kind of literals as String literals, Numeric literals, Boolean literals, special literal None and literal Collections. + Data Types: Data type is a set of values and the allowable operations on those values. Python has a great set of useful data types. Python's data types are built in the core of the language. They are easy to use and straight forward. CORE DATA TYPE a eo ia Intege er) 9s | Tuple fig Tr ¥ Numbers can be either integer/floating point or complex type numbers. v None: It is a special data type with a single value. It is used to signify the absence of value in a situation. v¥ A sequence is an ordered collection of items, indexed by integers starting from 0. Sequences can be grouped into strings, tuples and lists. - Strings are lines of text that can contain any character. They can be declared with double quotes. - Lists are used to group other data. They are similar to arrays. - A tuple consists of a number of values separated by commas. + A set is an unordered collection with no duplicate items. + Adictionary is an unordered set of key value pairs where the keys are unique. Page 6 of 20 Website: https:/ /www.leampythondchse.com/ (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs String List Tuple Set Dictionary immutable Mutable Immutable Mutable Mutable Ordered/Indexed | Ordered/Indexed | Ordered/Indexed | — Unordered Unordered Allows duplicate | Allows duplicate | Allows duplicate | Does not allow Does not allow values values values duplicate values duplicate keys Empty string="" | Empty list=[] Empty tuple=() | Emptyset=set() | Empty dictionary=(} String with single | Listwithsingle | Tuple with single | Setwith single | Dictionary with single element="A" | item=[*Apple"] | _item=("Apple",) | item={"Apple"} _| item=("Hello":1} Inside of dictionary key Iteanstore any | Itcanstore any | 29 nee 622 | canbe int, strand tuple Stores characters | data typestr, list, | data type str, list, | 'YPes (int. str, only values can be of ° tuple) but not ° or strings set, tuple, int and | set, tuple, intand | icy so, any data type int, str, dictionary dictionary » set, list, tuple, set and dictionary) dictionary. + Operator: Operators are special symbols which perform some computation. Operators and operands form an expression. Python operators can be classified as given below : Operators J | Bitwise Membership operators | | operators | | Arithmetical} | Relational operators | | operators or & * and | * not “ / ~ % << Es >> 4 Page 7 of 20 Website: https:/ /www.leampythondchse.com/ (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs + Punctuator: These are symbols that are used in a programming language to organise programming sentence structures and indicate the rhythm and emphasis of expression, statements and program structure. + Expressions: An expression in Python is any valid combination of operators, literals and variables. Ex 1. How will the following expression be evaluated in Python? 15.0/4 + (8 + 3.0) Solution: = 15.0/4 + (8.0 + 3.0) #Step 1 = 15.0/ 4.0 + 11.0 #Step 2 = 3.75 + 11.0 #Step 3 = 14.75 #Step 4 Ex 2. print(16*5/4*2/5-8) (CBSE-2023-24) Ans: 0.0 + L-value and R-value: Python uses the concept of L-value and R-value that is derived from the typical mode of evaluation on the left and right side of an assignment statement. + L-value: This concept refers to the requirement that the operand on the left side of the assignment operator is modifiable, usually a variable. + R-value: This concept pulls of fetches the values of the expression or operand on the right side of the assignment operator. INPUT AND OUTPUT FUNCTION + The print () function: v The print() function is a built-in function. It prints/outputs a_ specified message to the screen/consol window. Page 8 of 20 Website: https:/ /www.leampythondchse.com/ (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs v The print() function allows you to print out the value of a variable and strings in parenthesis. v The print() function will print as strings everything in a comma-separated sequence of expressions, and it will separate the results with single blanks by default. v The print() function automatically appends a newline to output. To print without a newline, use end separator after the last object. v The sep separator is used between the values. It defaults into a space character. For example: >>> print (10,20,30,40, sep='*") # prints a separator * 10*20*30*40 ¥ This ‘end’ is also optional and it allows us to specify any string to be appended after the last value. For example: >>> print (10,20,30,40, sep='*", end=’@’) # Anew end is assigned @ 10*20*30*40@ In the above example @ printed at the end of line. + The input (): ¥ The input() function is able to read data entered by the user and to return the same data to the running program. ¥ The input() function is invoked with one argument - it's a string containing a message v The message will be displayed on the console before the user is given an opportunity to enter anything. v The result of the input() function is a string. Page 9 of 20 Website: https:/ /www.leampythondchse.com/ (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs Link for Video Explanation of Revision Tour - 1: Video 1: https://youtu.be/eqDFuhGhoPg Video 2: https://youtu.be(QkP_XpedEow A program's Control flow is the order in which the program's code executes. The control flow of a Python program is regulated by conditional statements, loops, and function calls. Python has three types of control structures: + Sequential - default mode * Selection - used for decisions and branching + Repetition - used for looping, i.e., repeating a piece of code multiple times. 1. SEQUENTIAL Sequential statements are a set of statements whose execution process happens in a sequence. The problem with sequential statements is that if the logic has broken in any one of the lines, then the complete source code execution will break. 2. SELECTION/DECISION CONTROL STATEMENTS In Python, the selection statements are also known as Decision control statements or branching statements. The selection statement allows a program to test several conditions and execute instructions based on which condition is true. Some Decision Control Statements are: + Simple if + if-else * nested if + if-elif-else Page 10 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs Simple if: If statements are control flow statements that help us to run a particular code, but only when a certain condition is met or satisfied. A simple if only has one condition to check. # If the number is positive, we print an appropriate message if num > 0: print(num, “is a positive number.") print("This is always printed.") num = -1 if num > 0: print(num, “is a positive number.") print("This is also always printed.” + if-else: The if-else statement evaluates the condition and will execute the body of if if the test condition is True, but if the condition is False, then the body of else is executed. EXAMPLE: Program to find the simple interest based upon number of years. If number of years is more than 12 rate of interest is 10 otherwise 15. Code: p = int(input("Enter any principle amount") ) t = int(input ("Enter any time")) if (t>10): si = p*t#10/100 else: si = p*t*15/100 print ("Simple Interest = ",si) Page 11 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) t» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs + if-elif-else: The if-elif-else statement is Start used to conditionally execute a statement If elf conditional Statement or a block of statements. mut Statements _/ EXAMPLE: Write a program to input any choice and to implement the following. Choice Find 1, Area of square 2. Area of rectangle <2" ee TRUE _ (UTRIE=B6GY) 3. Area of triangle FALSE Code: supe c = int(input ("Enter any next sXtement Choice") ) if(c==1): s = input("enter any side of the square") a = sts print ("Area = ",a) elif (c==2): 1 = int(input("enter length") ) b = int(input("enter breadth") ) a= 1*b print ("Area = ",a) elif (c==3) : int (input ("enter first side of triangle")) y = int(input ("enter second side of triangle")) z = int(input("enter third side of triangle") ) Page 12 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs s = (xtytz)/2 A= ((s-x)*(s-y) *(s-2)) ##0.5 print ("Area=",A) else: print ("Wrong input") * nested if: Nested if statements are an if statement inside another if statement. EXAMPLE: Write a program using nested if — else construct to check a number is positive, negative or zero. Cod num = int(input(" Enter any number: ")) if num >= @: if num == 0: print ("Number is Zero" ) Nested ifconstruct else: print ("Number is Positive " ) else: print (" Number is Negative " ) 3. REPETITION for loop Iterating in A repetition statement is used to repeat a ‘Sequence group(block) of programming instructions. In Python, we generally have two loops/repetitive statements: + for loop + while loop Now statement Page 13 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs + for loop: A for loop is used to iterate over a sequence that is either a list, tuple, dictionary, or a set. We can execute a set of statements once for each item in a list, tuple, or dictionary. Python has a built-in function called range() that can generate a list of numbers. For example: ex = list(range(0, 10)) print (ex) Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Syntax of range () Function: range (start, stop, step) The number we How much we want to start want to count by counting at The number we The name of the want to count UP TO function (but will not include) + start is an optional parameter specifying the starting number of the sequence (0 by default) + stop is an optional parameter specifying the end of the sequence generated (it is not included), + and step is an optional parameter specifying the difference between the numbers in the sequence (1 by default.) Page 14 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback @) t» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs EXAMPLE: Write a program to input any number and to find sum of all natural numbers up to given number. n = int(input("Enter any number: ")) sum= 0 for i in range(1,n+1): sum sumti print ("sum=",sum) Output: Enter any number: 5 sum = 15 EXAMPLE: Write the output from the following code: sum = 0 for i in range(1,11,2): sumt = i print ("sum =", sum) output: sum = 25 + while loop: In Python, while loops are used to execute a block of statements repeatedly until a given condition is satisfied. Then, the expression is checked again and, if it is still true, the body is executed again. This continues until the expression becomes false. Exte while loop Page 15 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs EXAMPLE: Write a program to input any number and to find reverse of that number. n = int(input("Enter any number") ) r=0 while (n>0) : x = r¥10+n810 n = n/10 print ("reverse number is", r) EXAMPLE: Write the output from the following code: print ("Sum = ",sum) output: Sum = 60 + Nested Loop: Nested loops mean loops inside a loop. For example, while loop inside the for loop, for loop inside the for loop, etc. Output for i in range(2): a print(i) 10 Outer loop 11 for j in range(10,13): Printed 12 Inner loop by inner 1 < byouer rint( toep Je Ls Pp 3) cy 12 Printed Page 16 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs We can have an ‘else’ block associated with while loop. The ‘else’ block is optional. It executes only after the loop finished execution. Example 6: According to ideal Hindu wedding rituals, marriage is not completed until bride and groom don't take 7 vows. vow=1 while vow<=' print( "Bride and Groom take vow no:",vow ) vow=1 else: print( "Congratulation... Wedding Completed" ) Output: Bride and Groom take vow no: 1 Bride and Groom take vow no: 2 Bride and Groom take vow no: 3 Bride and Groom take vow no: 4 Bride and Groom take vow no: 5 Bride and Groom take vow no: 6 Bride and Groom take vow no: 7 Congratulation... wedding completed Page 17 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) ¢» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs = Jump Statements Jump statements are used to transfer the program's control from one location to another. Means these are used to alter the flow of a loop like - to skip a part of a loop or terminate a loop There are three types of jump statements used in python. 1. break 2. continue 3. pass * Break : It is used to terminate the loop For Example: for val in "string": if val == break print (val,end=’ ‘) print ("The end") output str The end + Continue: Used to skip the rest of the statements of the current loop block and to move to next iteration, of the loop. Continue will return back the control to the beginning of the loop. It Can be used with both while & for. For Example: for letter in ‘Python’: if letter == ‘h’: continue print (letter,end='’) output Pyton Page 18 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (> 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs « Pass Statement : This statement does nothing. It can be used when a statement is required syntactically but the program requires no action. Use in loop : while True: pass # Busy-wait for keyboard interrupt (Ctrl+C) Previous Year Board Questions 2019-20 1. Write the names of any four data types available in Python. 2. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. 250 = Number WHILE Number<=1000: Af Number=>750: print (Number) Number=Number+100 else print (Number*2) NumbersNumber+50 2021-22 3. Find the invalid identifier from the following (a) name (b) break (c) section (a) mark12 4. Which of the following is an incorrect Logical operator in Python? (a) not (b) in (c) or (4) and 5. Which of the following is the correct output for the execution of the following Python statement? print(5 + 3 ** 2/2) (a) 32 (b) 8.0 (9.5 (4) 32.0 Page 19 of 20 Website: https://www.leampythondchse.com! (} About Us Website: https://www.leampythondcbse.com/ [= Feedback (@) (» 8076665624 PYTHON | ONLINECLASSES | COMPUTERSC. | INFORMATICS PRAC. | SAMPLEPAPERS | PYTHON MCQs 2022-23 6. State True or False. “Identifiers are names used to identify a variable, function in a program.” 7. Consider the given expression : 5<10 and 12>7 or not 7>4 Which of the following will be the correct output, if the given expression is evaluated? (a) True (b) False (c) NONE (4) NULL 8. Which of the following operators will return either True or False ? (2) += (b) != (= (a) *= 9. What will the following expression be evaluated to in Python? print(4+3*5 /3-5%2) (a) 8.5 (b) 8.0 (©) 10.2 (4) 10.0 2023-24 10. What will be the output of the following statement: print(16*5/4*2/5-8) (a) -3.33 (b) 6.0 (c) 0.0 (a) -13.33 11. Identify the statement from the following which will raise an error: (a) print("a"*3) (b) print(5*3) (ec) print("15"+3) (4) print"15"+"13") Links for Video Explanation of Revision Tour - 1: Video 1: https://voutu.be/eqDFuhshoPg. Video 2: https://voutu.be/QkP_XpedEow, hanks- Page 20 of 20 Website: https://www.leampythondchse.com!

You might also like