wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming | Dayita

Total questions: 50

Worksheet time: 31mins

Name
Class
Date
1.

What does the following code do? myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

Converts the var (variable) myAge to if statement

2.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
3.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
4.

Python is ___________ level programming language and is ___________.

a)

High, compiled

b)

High, interpreted

c)

Low, compiled

d)

Low, interpreted

5.

A string

a)

carries out an action

b)

the elements of a command

c)

a collection of characters

d)

how elements in a commad are arranged

6.

what does this code display:
counter = 1

while counter <4:

                print (counter)

counter = counter + 1

a)

1 2 3 4

b)

1 2 3

c)

0 1 2 3

d)

0 1 2 3 4

7.

Which of these codes is the correct syntax?

a)

Print ("Hello World")

b)

print ("Hello World")

c)

PRINT ("Hello World")

d)

print "Hello World"

8.

What is the output of the following code?

def calculate (num1, num2):

answer = num1 * num2

print(answer)

calculate(2, 5)

a)

11

b)

7

c)

10

d)

answer

9.

What will be the output of this code? x = [1, 2, 3] print(len(x))

a)

3

b)

2

c)

1

d)

Error

10.

What would be the value of ‘new_score’ after running this code:
score = 44
total = 1

new_score = score * 2

a)

88

b)

44

c)

45

d)

22

11.

What is the output of the following code? x = 5 print(x * 2)

a)

10

b)

5

c)

25

d)

Error

12.

What will be the output of print("hello" + 1 + 2 + 3)?

a)

Error

b)

hello123

c)

hello6

d)

"hello"123

13.

Which of the following checks if x is not equal to y?

a)

if x not = y:

b)

if x == y:

c)

if x =! y:

d)

if x != y:

14.

Code to check if the variable x is less than 20.

a)

if x <> 20:

b)

if x <= 20:

c)

if x <= 20

d)

if x < 20:

15.

Which operator performs exponentiation?

a)

**

b)

*

c)

%

d)

/

16.

Takes the square root of x and returns a float.

a)

math.random(x)

b)

import.math(x)

c)

sqrt.math(x)

d)

math.sqrt(x)

17.
I want to allow the program to repeatedly ask the user to enter their guess if it does not equal the answer...Which option do I use?
a)
while guess == answer:
    guess=input()
b)
while answer != guess:
guess=input()
c)
while answer =! guess:
guess=input()
d)
while guess != answer:
guess=input()
18.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
19.
What does the APPEND procedure do in the following code:
teams = [“Man Utd”,“Man City”,"Arsenal"]

teams.append(“Liverpool”)
a)
Deletes Liverpool from the list
b)
Adds Chelsea to the list 
c)
Removes Arsenal from the list
d)
Adds Liverpool the list
20.
What would be the value of ‘marks’ after running this code:
 
marks = 20
total = 5 
newmarks = marks * 3
a)
60
b)
45
c)
100
d)
75
21.
What is printed when this program is run:
days = 5 
if days > 6:  
   print(“Month”)

else:  
   print(“Week”)
a)
Month
b)
Week
c)
Day
d)
4
22.

Which has integer data type?

a)

Phone number

b)

Zip code

c)

HN

d)

Number of students in the class

23.

There are 40 students in a classroom. We would like to get all students whose name starts with "A". Which looping is suitable?

a)

For loop

b)

While loop

24.

You are in the car with traffic jammed at a junction. To cross that junction according to the traffic rules, which one is NOT applicable

a)

While loop

b)

Conditional Statement

c)

For loop

25.
What will the output be from the following code?
print(3*4+5)
a)
27
b)
17
c)
12
d)
SyntaxError
26.
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
a)
Good moning 'Dave'
b)
Good morning Dave
c)
Good morning name
d)
Good morning + Dave
27.
How many times will this loop run?
a)
10
b)
9
c)
4
d)
5
28.

Anil is writing a "rock, scissors, paper" program. He wants the game to repeat until the user doesn't want to play anymore. What loop should he use?

a)

a FOR loop

b)

a WHILE loop

29.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
30.
Which of the following best describes the order in which these lines are processed in Python?
a)
4, 1, 2
b)
4, 2, 1
c)
1, 2, 3, 4
d)
3, 1, 2
31.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
32.
a)

i i i i i i

b)

a a a a a a

c)

a a a a a

d)

None

33.
a)

Working

b)

Stopped

c)

Error

d)

None

34.

What will be the output of the following code?

a)
  • A. 2

b)
  • B. 4

c)
  • C. 8

d)
  • D. 16

35.

What will be the output of the following code?

a)
  • A. Inner

b)
  • B. Outer

c)
  • C. Error

d)
  • D. None

36.

What will be the output?

S=50.6

number=int(S)

new_number=number-1

print(new_number)

a)

49.6

b)

49

c)

50

d)

51.6

e)

52

37.

What output will this code produce?

Colours=[]

Colours.append(“blue”)

Colours.append(“green”)

Colours.append(“red”)

Print(colours[2])

a)

blue

b)

green

c)

red

d)

error

e)

none of these

38.

Why are local variable names beginning with an underscore discouraged?

a)

they are used to indicate a private variables of a class

b)

they confuse the interpreter

c)

they are used to indicate global variables

d)

they slow down execution

39.

Which of the following statements create a dictionary?

a)

d = {}

b)

d = {"brand": "Tesla","electric": True}

c)

d = {2012:"Model S", 2016:"Model 3"}

d)

d = {"brand": "Tesla","electric": True,"colors": ["red", "white", "blue"]}

e)

All of the mentioned

40.

What is the output of the following lines

list = [[1, 3]]

list = list * 2

list[0][0] = 10

print(list)

a)

[[1, 3], [1, 3]]

b)

[[10, 3], [1, 3]]

c)

[[1, 10], [1, 3]]

d)

[[10, 3], [10, 3]]

41.

people = ["John", "Rob", "Bob"]

print (people[-1])

what would this result be?

a)
John
b)
Rob
c)
Bob
42.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

a.items()

a)

items()

b)

dict_items([(1,2,3)])

c)

dict_items([(‘A’), (‘B’), (‘C’)])

d)

dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

43.

What is the output of the given below program?

print("Know Program".split())

a)

‘Know’, ‘Program’

b)

(‘Know’, ‘Program’)

c)

[‘Know’, ‘Program’]

d)

{‘Know’, ‘Program’}

44.

Suppose a function called add() is defined in a module called adder.py. Which of the following code snippets correctly show how to import and use the add() function? Select all that apply.

a)

from adder import add

result = adder.add(2, 3)

b)

from adder import add

result = add(2, 3)

c)

import add from adder

result = add(2, 3)

d)

import adder

result = adder.add(2, 3)

45.

Find the output of the following program segments:

for i in range(20,30,2):

print(i)

a)

20 22 24 26 28

b)

20

22

24

26

28

c)

20 22 24 26 28 30

d)

20

22

24

26

28

30

46.

Which one of the following if statements will not execute successfully?

1) if (1, 2);

print(‘foo’)

2) if (1, 2):

print(‘foo’)

3) if (1):

print( ‘foo’ )

4) if (1);

print( ‘foo’ )

a)

1,4

b)

2

c)

2,4

d)

4

47.

Predict the output of the following code:

x=3

If x>2 or x<5 and x==6:

Print(“ok”)

else:

print(“no output”)

a)

ok

b)

okok

c)

no output

d)

none of above

48.

Who is the founder of Python Programming Language?

a)

Rasmus Ganilo

b)

Dennis Ritchie

c)

Guido van Rossum

d)

James Gosling

49.

File extension of Python program is ______

a)

.py

b)

.p

c)

.pyx

d)

.pyy

50.

List index begins with _________.

a)

0

b)

1

c)

-1

d)

-2