IMPORTANT CLASS 11 Python Questions
IMPORTANT CLASS 11 Python Questions
•
• Find out the maximum and minimum element from the array. (Don’t use any function)
• Find out the difference between maximum and minimum elements of the list.
• Arrange the elements of a list in increasing order of their value.
• Arrange the elements of a list in decreasing order of their value.
• Read a number from the keyboard and check whether the entered number is present or not in the list. If present, then also print the occurrences of
a entered number.
• Find out the average of n elements.
• Find out the sum of each elements in the list.
• Find out the total number of even elements in the list.
• Find out the total number of odd elements in the list.
• Suppress all zero elements at the bottom of the list.
• Suppress all negative elements at the bottom of the list.
• Suppress all positive elements at the bottom of the list.
• Suppress all non-zero elements at the bottom of the list.
• Return the largest even number from the list, if there is no even number in the input, print “Even not found in the list”.
• WAP to calculate compound simple interest after taking the principle, rate and time.
• Sort List Of Tuples By The First Element
• Sort List Of Tuples By Second Element
• Remove duplicate from list of tuples using dict() function
• convert two list to dictionary in Python
• Write a program to create mixed datatype tuple in Python
• Code to find the positive elements tuple from the list of Tuples
• Program to generate random number in Python
• Bubble sorting
• Insertion sorting
• WAP to calculate simple interest.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• WAP that asks your height in centimeters and converts it into foot and inches.
• WAP to find area of a triangle.
• Write a Program to obtain temperature in Celsius and convert it into Fahrenheit using formula – C X 9/5 + 32 = F
• WAP to read todays date (only date Part) from user. Then display how many days are left in the current month.
• WAP to print the area of circle when radius of the circle is given by user.
• WAP to print the volume of a cylinder when radius and height of the cylinder is given by user.
• WAP to check the given year is leap year or not.
• WAP to take two numbers and check that the first number is fully divisible by second number or not
• WAP to take the temperatures of all 7 days of the week and displays the average temperature of that week.
• WAP to calculate the roots of a given quadratic equation.
• WAP to check whether square root of a given number is prime or not
• WAP to print first n odd numbers in descending order.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• What is the extension of Python language?
Answer: All Python files have extension “.py”.
• Which mode of Python invoking the interpreter without passing a script file as a parameter?
Answer: Interactive Mode Programming.
• Which mode of Python invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished?
Answer: Script Mode Programming.
• Give a example of immutable data type.
Answer: Tuple.
• Which data type consists of a number of values separated by commas ?
Answer: tuple
• What is the difference between a keyword and an identifier ?
Answer:
Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are few. For example : if, else, elif etc.
Identifier is the user-defined name given to a part of a program like variable, object, functions etc. Identifiers are not reserverd. These are defined
by the user but they can have letters, digits and a symbols underscore. They must begin with either a letter or underscore. For example : chess, _ch,
etc.
• What are literals in Python ? How many types of literals are allowed in Python ?
Answer: Literals mean constants i.e. the data items that never change value during a program run. Python allow five types of literals :
• String literals
• Numeric literals
• Boolean literals
• Special literal (None)
• Literal collections like tuples, lists etc.
• 11. How many ways are there in Python to represent an integer literal ?
Answer: Python allows three types of integer literals :
• Decimal (base 10) integer literals.
• Octal (base 8) integer literals.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Hexadecimal (base 16) integer literals.
For example, decimal 12 will be written as 14 as octal integer and as OXC as hexa decimal integer. (12)10 = (14)8 = (OXC)16. (as hexa decimal)
• 12. What is “None” literal in Python ?
Answer: Python has one special literal called ‘None’. The ‘None’ literal is used to indicate something that has not yet been created. It is also used to
indicate the end of lists in Python.
• 13. What is the difference between a tuple and a list ?
Answer: A tuple is immutable i.e. cannot be changed. It can be operated on only. But a list is mutable. Changes can
be done internally to it.
tuple initialization: a = (2,4,5) list initialization: a = [2,4,5]
• 14. What does ‘immutable’ mean ? Which data type in Phython are immutable.
Answer: An immutable variable change of value will not happen in place. Modifying an immutable variable will rebuild the same variable. For
example,
>>> x= 5
will create a value 5 referenced by
x x —> 5
>>> y = x
This statement will make y refer to 5 of x.
x
5
y
>>> x = x + y
As x being, immutable type, has been rebuild. In the statement expression of RHS will result into value 10 and when this is assigned to LHS (x), x will
rebuild to 10. An Integer data type in python is immutable.
• 15. Which of the following variable names are invalid? Justify.
(a) try
(b) 123 Hello
(c) sum
(d) abc@123
Answer:
(a) try : is a keyword can’t be used as an identifier.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
(b) 123 Hello : Variable names can’t start with a digit.
(c) abc@123 : Special characters aren’t allowed in variable names.
• 16. Who developed python?
• Answer: Guido van Rossum
• 17. Python is an interpreted language‟. What does it mean to you?
• Answer- It means that the Python installation interprets and executes the code line by line at a time.
• 18. What does a cross platform language mean?
• Answer- it means a language can run equally on variety of platforms-Windows, Linux/UNIX, Macintosh, Supercomputers, Smart phones etc.
• 19. What is the difference between Interactive mode and Script Mode in Python?
• Answer- In interactive mode, one command can run at a time and commands are not saved. Whereas in Script mode, we can save all the
commands in the form of a program file and can see output of all lines together.
• 20.Which of the following are not valid strings in Python?
• (a)‖Hello‖ (b) ‗Hello‘ (c)‖Hello‘ (d) ‗Hello‖ (e) {Hello}
• Answer- String (c) , (d) and (e ) are not valid strings.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• PYTHON FUNDAMENTALS
• Q.1 What is None literal in Python?
• Ans: Python has one special literal, which is None. The None literal is used to indicate absence of value. It is also used to indicate the end of lists in
Python. It means ―There is nothing here‖.
• Q.2 What is the error in following code:
• x, y =7 ?
• Ans: The following error comes - 'int' object is not iterable. Which means an integer object i.e. cannot be repeated for x and y. one more integer
object is required after 7.
• Q.3 what will the following code do:
• a=b=18 ?
• Ans: This code will assign 18 to a and b both.
• Q.4 Following code is creating problem X = 0281, find reason
• Ans: 0281 is an invalid token.
• Q.5 Find the error in the following code:
• temp=90
• a=12
• print(“x=”x)
• Print temp b = a + b
• print( a And b)
• a, b, c=2, 8, 4
• x = 23
• else = 21-4
• print(a, b, c)
• 4=x
• c, b, a = a, b,
• c print(a; b; c)
• Ans: (a) Missing parentheses in call to 'print'.
• (b) Name ‗b‘ is not defined.
• (c) Invalid Syntax.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• (d) Invalid Syntax in second print statement.
• (e) can't assign to literal in second line.
• Invalid Syntax
• Expression • Statement
• It is a combination of letters, numbers and symbols • It is a programming instruction written according to python syntax
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Example: (25 + 7) / 4 • Example: If x<100:
• 9. What are literals in Python? How many types of Literals allowed in Python?
• Ans: Literals: Python comes with some built-in objects. Some are used so often that Python has a quick way to make these objects, called literals.
The literals include the string, Unicode string, integer, float, long, list, tuple and dictionary types
• 10.What are tokens in Python? How many types of tokens allowed in Python? Ans: Tokens are the smallest unit of the program.
• There are following tokens in Python:
• Reserved words or Keywords
• Identifiers
• Literals
• Punctuators
• Operators
• What are operators? What is their function? Give examples of some unary and binary operators.
• Ans: “Operators are those symbols used with operands, which tells compiler which operation is to be done on operands
• In other words – ―operators are tokens that trigger some computation/action when applied to variables and other objects in an expression.
• Operators are of following types: Unary operators like (+) Unary Plus, (-) Unary Minus, not etc.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Binary Operators like (+) addition, (*) multiplication, and etc
• What is the role of indentation in Python?
• Ans: Indentation plays a very important role in Python. Python uses indentation to create blocks of code. Statements at same indentation level are
part of same block/suit. You cannot unnecessarily indent a statement; python will raise an error for that.
• Ans: output:
• 17 , 5
• Data handling
• Q.1 Identify the data types of the following values given bellow – 3, 3j, 13.0, „12‟,”14”, 2+0j,19, [1,2,3],(3,4,5)
• Ans: 3 – int
• 3j – complex
• 13.0 – float
• 12‘ – string ―14
o string 2+0j – complex
• 19 – int
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• [1,2,3] – list
• (3,4,5) – tuple
• Q.2 What will be the output of the following
• (a)12/4 (b)14//14 (c)14%4 (d) 14.0/4 (e) 14.0//4 (f)14.0%4
• Ans: (a) 3.0 (b) 1 (c) 2 (d) 3.5 (e) 3.0 (f) 2.0
• Q.3 int(“a”) produces error. Why?
• Ans: This is because ‘a‘ is an invalid literal for int() with base 10.
• Q.4 What are data types? What are Python‟s built-in core data types?
• Ans: Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are
instance (object) of these classes. There are various data types in Python. Some of the important types are listed below. (i) Numbers (ii) String (iii)
List (iv) Tuple (v) Dictionary
• Q.5 Which data types of Python handle Numbers?
• Ans: It is cleared by name that Number data types are used to store numeric value in Python. The Numbers in Python have following core data
types: (i) Integers a. Integers (signed) b. Booleans (ii) Floating-Point Numbers (iii) Complex Numbers
• Q.6 Why is Boolean considered a subtype of Integers?
• Ans: Because Boolean Values False and True behave like the values 0 and 1, respectively. So Boolean type is a subtype of plain integers.
• Q.7 What are mutable and immutable types in Python? List both of them.
• Ans: Mutable types means those data types whose values can be changed at the time of execution.
• They are as follows: Lists• Dictionaries• Sets•
• Immutable types are those data types that can never change their value in place.
• In Python the following types are immutable: integers• floating-point numbers• Booleans• Strings• Tuples•
• Q.8 What are augmented assignment operators? How are they useful?
• Ans: An augmented assignment is generally used to replace a statement where an operator takes a variable as one of its arguments and then
assigns the result back to the same variable. A simple example is x += 1 which is expanded to x = x + (1). Similar constructions are often available for
various binary operators. They are helpful in making the source code small.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Conditional and iterative statements
o What a range() function does? Give an example.
• Ans: The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified
number. its syntax is range(start, stop, step)
• e.g.
• x = range(3, 6)
• for n in x:
• print(n)
• #This code will print 3 4 5
o What are loops in Python? How many types of loop are there in Python?
• Ans: Loops are iteration constructs in Python. Iteration means repetition of a set of statements depending upon a condition test. Loops has three
basic elements within it to repeat the statements – Initialization (Start)• Check Condition (Stop)• Updation (Step)•
• Python provide two types of loop (i) Conditional Loop while (Condition based loop) (ii) Counting loop for (loop for a given number of times).
• What is the syntax of if-elif statement in Python?
• Ans: The syntax of if-elif statement in python is as follows:
• If condition1: #code-block of statements when condition1 is true
• elif condion2: #code-block of statements when condition2 is true
• elif condition3: #code-block of statements when condition3 is true . . .
• else: #code-block of statements when all above conditions are false.
• What are jump statements in Python? Name jump statements with example.
• Ans: Python offers two jump statements to be used with in loops to jump out of loop-iterations. These are break and continue statements.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• STRING MANIPULATION AND DEBUGGING PROGRAMS
• Q.1 which of the following is not a Python legal string operation?
• (a)‟abc‟+‟abc‟ (b) ”abc‟*3 (c)‟abc‟ + 3 (d)‟abc‟.lower()
• Ans: (c) “abc‘ + 3
• Q.2 Out of the following operators, which ones can be used with strings?
• =, -, *, /, //, %, >, <>, in, not in, <=
• Ans: /, // and %
• Q.3 From the string S = “CARPE DIEM”. Which ranges return “DIE” and “CAR”?
• Ans: S[6:9] for ―DIE and S[0:3] for ―CAR
• Q.4 Write a python script that traverses through an input string and prints its characters in different lines – two characters per line.
• Q.5 Which functions would you chose to use to remove leading and trailing white spaces from a given string?
• Ans: Python String strip() function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip() or
rstrip() function instead.
• Q.6 Suggest appropriate functions for the following tasks –
• To check whether the string contains digits.
• To find the occurrence a string within another string.
• To convert the first letter of a string to upper case.
• To convert all the letters of a string to upper case.
• To check whether all the letters of the string are in capital letters.
• to remove all the white spaces from the beginning of a string.
• Ans:
• isalnum() (b) find() (c) capitalize() (d) upper() (f) isupper() (g) lstrip()
• Q.7 What do you understand by Syntax errors and Semantics errors?
• Ans: Syntax Errors: syntax error occur when rules of a programming language are misused i.e. grammatical rule of Python is violated.
• e.g. X<-x*y if x=(x*y) etc.
• Semantics Errors: Semantics error occur when statements are not meaningful.
• E.g. x * y = z this will result in a semantically error as an expression cannot come on the left side of an assignment operator.
• Q.8 what are main error types? Which types are most dangerous and why?
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Ans: Main error types are - (i) Compile-time errors (ii) Run-time errors (iii) Logical errors Logical errors are most dangerous errors because these are
most difficult to fix. The error is caused by a mistake in the program‘s logic. You won‘t get an error message, because no syntax or runtime error has
occurred. You will have to find the problem on your own by reviewing all the relevant parts of your code – although some tools can flag suspicious
code which looks like it could cause unexpected behavior.
• Q.9 Name some common built-in exceptions in Python.
• Ans: Some Common built-in Exceptions in Python are:
• EOF Error (ii) IO Error (iii) Name Error (iv) Index Error
• (v) Import Error (vi) Type Error (vii) Value Error (viii) Zero Division Error (ix) Key Error
• Q.10 What is debugging and code tracing?
• Ans: Debugging involves correction of code so that the cause of errors is removed. In other words we can say that debugging means figure out the
origin of error in code, fix the error code and review and rerun your code to ensure that the error is fixed.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• ListName[start:stop]
• Q.6 1 How are lists different from strings when both are sequences?
• Ans: Lists are similar to strings in many ways like indexing, slicing, and accessing individual elements but they are different in the sense that
• Lists are mutable while strings are immutable.
• In consecutive locations, strings store the individual characters while list stores the references of its elements.
• Strings store single type of elements-all characters while lists can store elements belonging to different types.
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• >>>T=() or >>>T=tuple()
• Q.14 What is the difference between (30) and (30,)?
• Ans: (30) is an integer while (30,) is a tuple.
• Q.15 Why can‟t List can be used as keys?
• Ans: List is mutable datatype. And Keys of dictionary must be immutable type. This is the region that list cannot be used as keys
• Q.16 What type of objects can be used as keys in dictionary?
• Ans: Any immutable objects can be used as keys in dictionary.
• Q.17 Can you change the order of the dictionaries contents?
• Ans: Yes, the order of dictionary contents may be changed.
• Q.18 Can you modify the keys in a dictionary?
• Ans: Keys cannot be modified in dictionary while values are mutable in dictionary.
• Q.19 How is clear() function different from del Statement?
• Ans: clear() removes all the elements of a dictionary and makes it empty dictionary while del statement removes the complete dictionary as an
object. After del statement with a dictionary name, that dictionary object no longer exists, not even empty dictionary.
• Q.20 WAP to create a dictionary named year whose keys are month names and values are their corresponding number of days.
• Understanding Sorting
• Q.1 What is sorting? Name some sorting Techniques.
• Ans: In computer terms sorting refers to arranging elements in a specific order – ascending or descending. Some sorting techniques are – (i)
Selection Sort (ii) Bubble Sort (iii) Insertion Sort (iv) Heap Sort (v) Quick Sort
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Q.3What is the basic principal of sorting in Insertion sort?
• Ans: Insertion sort is a sorting algorithm that builds a sorted list by taking one element at a time from the unsorted list and by inserting the element
at its correct position in sorted list
• Q.4What is the main difference between insertion sort and bubble sort techniques?
• Ans: Bubble Sort - It is a sorting algorithm in which two adjacent elements of an array are checked and swapped if they are in wrong order and this
process is repeated until we get a sorted array. In this first two elements of the array are checked and swapped if they are in wrong order. Then first
and third elements are checked and swapped if they are in wrong order. This continues till the lat element is checked and swapped if necessary.
Insertion Sort - In this, the second element is compared with the first element and is swapped if it is not in order. Similarly, we take the third
element in the next iteration and place it at the right place in the sub-array of the first and second elements (as the subarray containing the first
and second elements is already sorted). We repeat this step with the fourth element of the array in the next iteration and place it at the right
position in the subarray containing the first, second and the third elements. We repeat this process until our array gets sorted.
• BOOLEAN LOGIC
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• What is SQL? What are different categories of commands available in SQL?
• Differentiate between DDL and DML commands.
• Differentiate between CHAR and VARCHAR Datatypes
• Write SQL commands to perform the following tasks –
• Create table Employee with the following structure:
• Name of Column ID First_Name Last_Name User_ID Salary
• Type Number (4) Varchar(30) Varchar(30) Varchar(10) Number(9,2)
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.
• Online access and computer security
• 1.What is a virus? What is anti-virus software?
o What is Computer virus? How can it affect your computer?
o What are different types of threats to computer security?
• 4.What are malware? What type damages can they cause to your computer?
o What do you understand by PC intrusion?
o How is pharming similar to and different from phishing?
• 7.What is the significance of Firewall in a computer‟s security scheme?
o What is Eavesdropping? What security measures can you take up to prevent it?
www.programmingwithmaurya.com
© This Content is for private use only. Circulation via any medium is illegal and liable to strict actions.