wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON PROGRAMMING

Total questions: 15

Worksheet time: 5mins

Name
Class
Date
1.

1. What is the output of the following code?


var1 = 1

var2 = 2

var3 = "3"

print(var + var2 + var3)

a)

6

b)

33

c)

123

d)

ERROR

2.

2. What is the output of the following code?


p, q, r = 10, 20 ,30

print(p, q, r)

a)

10 20

b)

10 20 30

c)

Error: invalid syntax

3.

3. What is the Output of the following code?


for x in range(0.5, 5.5, 0.5):

print(x)

a)

[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]

b)

[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

c)

The Program executed with errors

4.

4. What is the output of the following code?


salary = 8000


def printSalary():

salary = 12000

print("Salary:", salary)


printSalary()

print("Salary:", salary)

a)

Salary: 12000 Salary: 8000

b)

Salary: 8000 Salary: 12000

c)

The program failed with errors

5.

5. What is the output of the following code?


def calculate (num1, num2=4):

res = num1 * num2

print(res)


calculate(5, 6)

a)

20

b)

The program executed with errors

c)

30

6.

6. Can we use the “else” clause for loops?

for example:

for i in range(1, 5):

print(i)

else:

print("this is else block statement" )

a)

YES

b)

NO

7.

7. A string is immutable in Python?

Every time when we modify the string, Python Always creates a new String and assigns a new string to that variable.

a)

TRUE

b)

FALSE

8.

8. What is the output of the following code?

sampleList = ["Jon", "Kelly", "Jessa"]

sampleList.append(2, "Scott")

print(sampleList)

a)

The program executed with errors

b)

[‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]

c)

[‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]

9.

9. What is the output of the following?

x = 36 / 4 * (3 + 2) * 4 + 2

print(x)

a)

182.0

b)

37

c)

117

d)

ERROR

10.

10. Which operator has higher precedence in the following list?

a)

% Modulus

b)

& BitWise AND

c)

**, Exponent

d)

> Comparison

11.

11. What is the output of the following code?

for i in range(10, 15, 1):

print( i, end=', ')

a)

10, 11, 12, 13, 14,

b)

10, 11, 12, 13, 14, 15,

12.

12. What is the output of the following code?


listOne = [20, 40, 60, 80]

listTwo = [20, 40, 60, 80]


print(listOne == listTwo)

print(listOne is listTwo)

a)

TRUE

TRUE

b)

TRUE

FALSE

c)

FALSE

TRUE

13.

13. The ‘in’ operator is used to check if a value exists within an iterable object container such as a list. Evaluates to true if it finds a variable in the specified sequence and false otherwise.

a)

TRUE

b)

FALSE

14.

14. What is the output of the following code?

str = "pynative"

print (str[1:3])

a)

py

b)

yn

c)

pyn

d)

yna

15.

15. What is the output of the following code?


valueOne = 5 ** 2

valueTwo = 5 ** 3


print(valueOne)

print(valueTwo)

a)

10

15

b)

25

125

c)

ERROR