Standard : X
Chapter 8: PYTHON REVISION.
Keywords:
1. Atom- Something that has a value.
group of consecutive statements having same
2. Block- A
identation level.
3. Literals- Constant
4. Keyword- Reserved word having special meaning and
purpose.
5. Body- The block of statement in a compound statement
that follows the header.
Q.1 Objective Type Questions
1. What will be the output of
Print 3*2**2
a) 81 b) 18 c) 36 d) 12
2. Which of these is not a python data type?
a) int b) long c) Float d) Number
3. What will be the output of
Print (3*2)**2
a) 81 b) 18 c) 36 d) 12
4. Which of the following has the highest precedence in an
expression?
a) Exponentiation(* *) b) Division(/)
c) Multiplication (*) d) Paranthesis {()}
5. What is the output of the following code?
a) 8>=8 b) False
c) True d) Error
Q.2 Answer the following.
1) What is the difference between a keyword and an identifier?
Ans- Keyword- It is a special word that has a special meaning and
purpose. Keywords are reserved and a few.
Example: if, else if, else etc. are keywords.
Identifier- It is a user-defined name given to a part of a program.
viz variable, object, function etc. Identifiers are not reserved. They
must begin with either a letter or underscore.
For instance, _chk, chess, trial etc. are identifiers in python.
2) Which data types of Python handle Numbers?
Ans- Python provides following data types to handle Numbers
(version 2.7)
i. Plain integers
ii. Boolean
iii. Long integers
iv. Complex Numbers
v. Floting-point Numbers
3) What are data types? What are Pythons built-in core data types?
Ans- The real-life data is of many types so to represent various types of
real-life data, Programming language provide various ways and facilities
to handle these which are known as data types:
Python’s built-in core data types belongs to:
a. List.
b. Tuple.
c. Dictionary.
d. String.
e. Numbers (Booleans, complex Numbers).
4) What are literals in Python? How many types of literals are allowed
in Python?
Ans: Literals are constant i.e. the data items that never change their
value during a Program Run.
Python allows five types of literals:
a. String literals.
b. Numeric literals.
c. Special literal. None.
d. Boolean literals.
e. Literal collection called tuples list.
Application Oriented Questions
1) Aniket wants to double the value of 5 and raise
it to power of 2.50 he wrote following expression
print5*2**2
a. What result did he get from his expression
b. Aniket has answer as 100 in mind. Is the answer produced
by above expression equal to 100?
c. What changes will you suggest to Aniket to get his desired
output?
Ans: a. 20
b. No, the answer is not equal to 100.The reason behind this is
that operator *, hence 2**2 is executed first and then multiplied with 5
c. (5*2) **2
i.e; use parenthesis to override precedence.
2. Consider the following code:
Print 11/2, 11/2
a) What will be the output of above code?
b) What changes will you make to get exact division of 11 with 2?
Ans: a) 5 5
b) print 11.0/2 , 11 |/2.
Chap:9 Python Conditionals And Loops
Keywords:
1. Suit-Block.
2. Block- A group of a consecutive statements having same
indentation level.
3. Body- The block of statements in a compound statement that
follows the header.
4. Infinite Loop- A Loop that never ends. Endless Loop.
5. Iteration statement- Looping statement.
6. Jump statement-Statement that unconditionally transfer
program control within a function.
7. Looping Statement- Iteration.
8. Empty Statement- A statement that appears in the code but
does nothing.
9. Nested Loop- A Loop that contains another Loop inside its
body.
10. Nesting-Same program-construct within another Loop inside
its body.
Objective Type Questions
1 .What is the output of following code?
While3>=3:
Print 3
a) 3 is printed once.
b) 3 is printed 3 times.
c) Error in code.
d) 3 is printed infinitely until program is closed.
2. What will be output of following code?
for i in range(1,0):
print i
a) 0
b) 1
c) No output
d) Error in code
3.What of the following is/are not a valid Python Loop?
a) for b)while
c) iter d)repeat
4. Which of the following is used to define a block of code?
a) { } c) identation
b) ( ) d) Quotation
Q.2 Answer the following Questions.
1. What are looping or iterative statements? Which simple looping
statements are provided by Python?
Ans. Looping or iterative statements are those that repeatedly carry
out a set of statements
Python provides two simple looping statements
1. For
2. While
2. What are selection or conditional statements? Which selection
statements are provided by Python?
Ans. Selection or conditional statements are those that let us specify
two different sets of commands that are executed on the basis of result
of a condition. If the condition is true a set of commands will be
executed, and if the condition is false, a different set of command will
get executed.
Python provides if and if-else statements are conditional statements.
3. What is output of following code?
If(4+5==0) :
print”TRUE”
else :
print”False”
print”TRUE”
Ans- FALSE
TRUE
4.Write python code to add the odd numbers up to a given value N and
print the result.
Ans- N = input (‘Enter Number’)
sum=0
i=1
while i<=N:
sum=sum+i
i=i+2
print sum
Python Programms(Practicals)
1. Write a python program to print squares of First 5 Natural
Numbers.
Ans. Num=1
while Num<=5;
Print Num*Num
Num=Num=1
Output:
16
25
2. Program to Print sum of Natural Numbers between 1to7.
Ans. sum=0
for n in range (1,8):
sum+=n
print “Sum of natural numbers <=”n,’is’,
sum
Output: Sum of Natural Numbers<=7 is 28
3. Program that takes a number and check whether the given
number is odd or even.
Ans. num=int(raw_input(“Enter an integer:”))
if num%2=0;
print num,”is Even number.”
else
print num,”is Odd number.”
Output:
Enter a Number: 8
- 8 is Even Number
4. Write a program to read distance in miles and print in kilometers.
Ans. miles=input(“Enter a distance in miles:”)
Kilometers=1.609*miles
Print”The distance in kilometers is,”Kilometers
Output:
Enter a distance in miles=3.5
Distance in kilometers is 5.6315