## Pre-Quiz

### Q1 – Dene what kind of language is python ?

Answer: Interpreted

Explanation:

The terms interpreted or compiled is not a property of the language but a property of the implementation. There are multiple
implementations of Python language. The ocial one is byte code ‘interpreted’. So, it is called as an interpreted language.

### Q2 – Object Oriented Programming is possible in Python. State whether ‘True’ or ‘False’

Answer: True

Explanation:

OOP is a programming paradigm or style where you code you logic in terms of Classes and Objects and the functionality is
implemented as interaction between these objects. Python supports OOP. You can code your logic in python using OOP or
Procedural or in Functional manner too.

### Q3 – Identify the correct operator for power(x^y).

Answer: x**y

Explanation:

The ** operator in Python is used to raise the number on the left of ** to the power of the exponent on the right of **.
Eg : 5 ** 3 ; 5 is being raised to the 3rd power.

### Q4 – Identify which one of these is oor division.

Answer: //

Explanation:

In Python 3, normal division (/) returns the quotient with decimal while oor division (//) returns the quotient after removing the
digits after the decimal point.

### Q5 – Mathematical operations can be performed on a string. State whether ‘True’ or ‘False’.

Answer: False

Explanation:

Mathematical operations cannot be performed on a string.

## Practice Session

### Q1 – Fill in the simple for loop to print even numbers from -10 to 10, excluding 0.

for i in range( ________ ):

if( ________ ):

continue

print(i)

-10,11,2

i == 0

### Q2 – Fill in the simple while loop to print numbers from -10 until 0 (0 inclusive).

num=-10

_____ (num ____ 0):

print(num)

num=num+1.

while

<=

## Post Quiz

### Q1 – Analyse and nd which of the following loops correctly computes 1/2 + 2/3 + 3/4 + … + 99/100.

A:

sum = 0

for i in range(1, 99):

sum += i / (i + 1)

print(“Sum is”, sum)

B:

sum = 0

for i in range(1, 100):

sum += i / (i + 1)

print(“Sum is”, sum)

C:

sum = 0

for i in range(1.0, 99.0):

sum += i / (i + 1)

print(“Sum is”, sum)

D:

sum = 0

for i in range(1.0, 100.0):

sum += i / (i + 1)

print(“Sum is”, sum)

Answer: B

Explanation:

Python range() doesn’t support the oat type. Hence, option C and D are invalid.

Option A is invalid because i takes values from 1 to 98 – last fraction in the sequence is 98/99, not 99/100. Option B is
correct.

### Q2 – Evaluate the given code and tell which single line of code can be used to replace this sample code?

nums = [1,2,3,4,5,6,7,8,9]

x = 0

for n in nums:

x = x + n

print(x)

Answer : print(sum(range(1,10)))

Explanation:

The code represents the logic for nding the sum of numbers from 1-9. In this case, range must be from 1-10. Hence, the
right syntax is : print(sum(range(1,10)))

### Q3 – Select the choices that should not appear in the place of EXP – given : for k in EXP:

Answer: a range of oat

Explanation:

A list in the place of EXP will take you through the list elements. A dictionary will take you through the key/value
pairs. A string will take you through its characters. A range of integers will take you through the integers within
the range. But a range of oat in the place of EXP in for is illegal.

### Q4 – Which statement best describes the behavior of the following expression?

x != 0 and y % x != 0

Answer: It executes successfully for all values of x

Explanation:

The expression is valid and it executes successfully for all values of x.

### Q5 – Analyse and predict the output for the following.

isCorrect = False

print(“Correct” if isCorrect else “Incorrect”)

Answer: Incorrect

Explanation:

“Correct” will get printed only if isCorrect is True. Since isCorrect is False, our output is Incorrect.

## Check Your Understanding

### Q1 – Arrange the following code

n=input()

sum=0

for i in range(0,n,1)

sum=sum+i

print(sum)

### Q2 – Find the missing part of the following code. To print the even numbers between 0 to n

__ =input()

for i in range( __ ,n, __ )

print( __ )

n

0

2

i

### Q3 – The else block can be included along with while loop

Answer: True

Explanation:

Python allows us to use the else condition with for/while loops. The else block is executed only when the loop is not
terminated by a break statement.

Python allows us to use the else condition with for/while loops. The else block is executed only when the loop is not
terminated by a break statement.

### Q4 – Match the following

x=bool(0)

y=bool(1)

if x:

print(x)

else:

print(y)

for i in range(1,2,2):

print(i)

n=2

for i in range(0,n,1):

if bool(i):

print(i)

True

1

1

### Q5 –

Tab space

indentation is used for the statements under loops