wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

L244P1 Basic Pyton Programming

Total questions: 20

Worksheet time: 10hrs 31mins

Name
Class
Date
1.

a = 2

b = 330

print("A") if a > b else print("B")

What is the Output?

a)

A

b)

B

c)

Error

d)

AB

2.

Which of the following is the correct extension of the Python file?

a)

.py

b)

.python

c)

.pyt

d)

.exe

3.

What will be the value of the following Python expression?

4 + 3 % 5

a)

7

b)

2

c)

4

d)

0

4.

Which of the following is used to define a block of code in Python language?

a)

{

}

b)

[ ]

c)

()

d)

Indendation

5.

Which of the following character is used to give single-line comments in Python?

a)

/

b)

//

c)

///

d)

#

6.

What will be the output of the following Python code snippet if x=1?

x<<2

a)

8

b)

2

c)

4

d)

1

7.

>>>what is the output of range(2,10,2)

a)

1,3,5,6,7

b)

2,4,6,8,10

c)

2,4,6,8

d)

2,4,6

8.

Which one of the following is correct way of declaring and initializing a variable, x with value 5?

a)

int x

x=5

b)

int x=5

c)

x=5

d)

declare x=5

9.

Which of the operator means less than equal to ?

a)

>

b)

<

c)

>=

d)

<=

10.

else: is used

a)

to give an extra condition

b)

to provide an output when the other conditions are false

c)

because it is required

d)

if we do not use it, it gives error

11.

Sonam has written this program in Python. One of the lines contains at least one error. Which line is it?

a)

print(“Hello world!”)

b)

name=input(‘please enter your name’)

c)

print(happy to meet you)

d)

print(‘you have great name’)

12.

An instruction is written to determine if the value in a is equal to the value in b.

Choose the correct operator to complete the instruction:

if a ______ b:

a)

<--

b)

=

c)

==

13.

Choose the operators to represent "not equal to" in PYTHON

a)

<>

b)

/=

c)

Not=

d)

!=

14.

What is the output of the following:

a=2

b=3

c=4

a=b

b=a

c=b

print(c)

(a)  

15.

What is the result of the following:

x = 10

m = x % 4

print (m)

(a)  

16.

A statement in the program that is not executed and can explain to another programmer what the code is about

(a)  

17.

Which of the following is the correct way to create a list in Python?

a)

list = <1, 2, 3>

b)

list = (1, 2, 3)

c)

list = [1, 2, 3]

d)

list = {1, 2, 3}

18.

What is the output of the following code snippet?

for i in range(3):

print(i)

a)

0 1 2 3

b)

0 1

c)

1 2 3

d)

0 1 2

19.

What will be the output of the following Python code snippet?

print(type(5.0))

a)

str

b)

NoneType

c)

float

d)

int

20.

What is the output of the following code snippet?

for i in range(1, 5):

print(i * 2)

a)

1 2 3 4

b)

2 4 6 8

c)

2 3 4 5

d)

1 3 5 7