Python classXI Notes
Python classXI Notes
Q.7 What are operators? What is their function? Give examples of some unary and binary
operators.
Prepared By: Sanjeev Bhadauria & Neha Tyagi
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.
Binary Operators like (+) addition, (*) multiplication, and etc.
Q.3 Which of the following are syntactically correct strings? State reason.
(a) ”Python is nice Language”
(b) „He called me “Friend!” when he came‟
(c) “Very Good‟
(d) „This is a good book‟
(e) “Namaste
(f) “I liked „Harry Potter‟ very much”
Ans: (a) Correct (b) Correct (c) Incorrect (d) Correct (e) Incorrect (f) Correct
Prepared By: Sanjeev Bhadauria & Neha Tyagi
Q.4 What is the error in following Python program with one statement?
print(“My name is : “, name)
suggest a solution
Ans: Error is : ―name 'name' is not defined‖. And the solution is to declare the variable-name before
this statement.
Ans: Output: 17 5
Q.6 What will be the output of the following code:
Ans: Output: Hari , you are 18 now but You will be 19 next year
Q.7 Write a Program to obtain temperature in Celsius and convert it into Fahrenheit using
formula –
C X 9/5 + 32 = F
Ans:
Q.8 Predict output:
Ans: Output: 4 6 8
Q.9 WAP to read todays date (only date Part) from user. Then display how many days are
left in the current month.
Ans:
Q.10 WAP to print the area of circle when radius of the circle is given by user.
Ans:
Q.11 WAP to print the volume of a cylinder when radius and height of the cylinder is given
by user.
Ans:
Prepared By: Sanjeev Bhadauria & Neha Tyagi
Q.12 WAP that asks your height in centimeters and converts it into foot and inches.
Ans:
Ans: 4
4.25
1
4
Q.4 What will be the output of the following ?
(a) bool(0) (b) bool(„0‟) (c) bool(int(„0‟))
(d) bool(str(0.0)) (e) bool(0j) (f) bool(0.0)
Ans: (a) False (b) True (c) False
(d) True (e) False (f) False
Q.5 What will be the output of the following ?
Prepared By: Sanjeev Bhadauria & Neha Tyagi
Q.6 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.7 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.
Q.3 WAP to take two numbers and check that the first number is fully divisible by second
number or not.
Ans:
Ans: -2
6561
Q.5 What will be the output of the following?
Ans: 4.0
Q.6 WAP to take value of x,y,z from the user and calculate the equation
Ans:
Q.7 WAP to take the temperatures of all 7 days of the week and displays the average
temperature of that week.
Ans:
Q.2 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).
Q.3 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.
Q.4 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.
Ans:
Q.6 What is the error in following code. Rewrite the correct code.
Correct
Code:
Prepared By: Sanjeev Bhadauria & Neha Tyagi
Ans:
Q.3 WAP to compute the result when two numbers and one operator is given by user.
Ans:
Q.6 WAP to check whether square root of a given number is prime or not.
Ans:
(ii)
Prepared By: Sanjeev Bhadauria & Neha Tyagi
Q.9 WAP to find the average of the list of the numbers entered through keyboard.
Ans:
Q.10 WAP to find the largest number from the list of the numbers entered through
keyboard.
Ans:
Q.11 WAP to find the 2nd largest number from the list of the numbers entered through
keyboard. (This program is from List Chapter)
Ans:
Ans: (a)
(b)
(c)
(d)