wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

test

Total questions: 85

Worksheet time: 51mins

Name
Class
Date
1.

Is Python case sensitive when dealing with identifiers?

a)

yes

b)

no

2.

What is the maximum possible length of an identifier?

a)

31 characters

b)

59 characters

c)

10 characters

d)

None of the mentioned

3.

Which of the following is invalid?

a)

_a = 1

b)

__a = 1

c)

__str__ = 1

d)

none of the mentioned

4.

Which of the following is an invalid variable?

a)

my_string_1

b)

1st_string

c)

__

5.

Which of the following is not a keyword?

a)

eval

b)

assert

c)

nonlocal

d)

pass

6.

All keywords in Python are in

a)

lower case

b)

UPPER CASE

c)

Capitalized

d)

True, False and None are capitalized while the others are in lower case.

7.

Which of the following is an invalid statement?

a)

abc = 1,000,000

b)

a b c = 1000 2000 3000

c)

a,b,c = 1000, 2000, 3000

d)

a_b_c = 1,000,000

8.

Which of the following cannot be a variable?

a)

__init__

b)

in

c)

it

d)

on

9.

What is the output of this expression, 3*1**3?

a)

27

b)

9

c)

3

d)

1

10.

Which of these in not a core data type?

a)

Lists

b)

Dictionary

c)

Class

11.

Given a function that does not return any value, What value is thrown by default when executed in shell.

a)

int

b)

bool

c)

void

d)

none

12.

Which of the following will run without errors ?

a)

round(45.8)

b)

round(6352.898,2,5)

c)

round()

d)

round(7463.123,2,1)

13.

What is the return type of function id ?

a)

int

b)

float

c)

bool

d)

dict

14.

What error occurs when you execute?

apple = mango

a)

SyntaxError

b)

NameError

c)

ValueError

d)

TypeError

15.

Which of the following results in a SyntaxError ?

a)

‘”Once upon a time…”, she said.’

b)

“He said, ‘Yes!'”

c)

‘3\’

d)

”’That’s okay”’

16.

What is the difference between a variable and a data type in Python?

a)

A variable is a type of data, while a data type is a specific value in Python.

b)

A variable is a name that refers to a value, while a data type specifies the type of data that a variable can hold.

c)

A variable and a data type are the same thing in Python.

d)

A variable is used for storing data temporarily, while a data type is used for performing operations in Python.

17.

How do you write an if-else statement in Python?

a)

if (condition) then { // code block } else { // code block }

b)

if (condition) { // code block } else { // code block }

c)

if condition { // code block } else { // code block }

d)

if condition: # code block else: # code block

18.

Explain the purpose of a function in Python and give an example.

a)

The purpose of a function in Python is to display a message on the screen. For example, print('Hello, World!')

b)

The purpose of a function in Python is to encapsulate a set of instructions that can be called multiple times to perform a specific task. For example, a function to calculate the area of a circle can be defined as follows: def calculate_area(radius): return 3.14 * radius * radius

c)

The purpose of a function in Python is to define a variable. For example, x = 5

d)

The purpose of a function in Python is to create a loop. For example, for i in range(5):

19.

How would you add element to an existing list?

a)

Using a function called append()

b)

by writing the name of the list and element together

c)

add_element() function

d)

A list cannot be further modified.

20.

How do you concatenate two strings in Python?

a)

string1 . string2

b)

string1 * string2

c)

string1 + string2

d)

string1 - string2

21.

Write a for loop that prints numbers from 1 to 10.

a)

for num in range(1, 11): print(num + 1)

b)

for num in range(1, 10): print(num)

c)

for num in range(10): print(num)

d)

for num in range(1, 11): print(num)

22.

Write a while loop that counts down from 10 to 1.

a)

while count > 0: print(count) count -= 1

b)

count = 10 while count > 0: print(count) count = count - 1

c)

for i in range(10, 0, -1): print(i)

d)

while count < 10: print(count) count += 1

23.

What are the different types of operators in Python?

a)

Arithmetic, Comparison, Logical, Assignment, Bitwise, Membership, Identity

b)

Addition, Subtraction, Multiplication, Division

c)

Equals, Not Equals, Greater Than, Less Than

d)

If, Else, While, For

24.

What is the purpose of using a dictionary in Python?

a)

To store data in key-value pairs

b)

To perform mathematical operations

c)

To create loops for iteration

d)

To define variables and data types

25.

Write a Python function to calculate the factorial of a number.

a)

def factorial(num): result = 1 for i in range(1, num + 1): result *= i return result

b)

def factorial(num): result = 0 for i in range(1, num + 1): result += i return result

c)

def factorial(num): result = 1 for i in range(1, num): result *= i return result

d)

def factorial(num): result = 1 for i in range(1, num + 1): result += i return result

26.

What is the purpose of using the 'break' statement in a loop in Python?

a)

To skip the current iteration and continue with the next iteration

b)

To exit the loop immediately

c)

To execute a specific block of code when a condition is met

d)

To repeat the loop for a specific number of times

27.

What is the purpose of using the 'continue' statement in a loop in Python?

a)

To skip the current iteration and continue with the next iteration

b)

To exit the loop immediately

c)

To execute a specific block of code when a condition is met

d)

To repeat the loop for a specific number of times

28.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
29.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
30.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

31.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
32.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
33.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
34.
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
35.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)

It displays an output

d)
It loops the code.
36.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
37.

What is the output from the following code?

print ("hello world")

a)
Hello World
b)
hello world
c)
print hello world
38.

What is the Python built-in function used to display numbers and text on the screen?

a)

print

b)

input

c)

output

d)

command

39.

The punctuation requirements for printing a string in Python are:

a)

( ) , ! and " "

b)

( ) and !

c)

( ) and " "

d)

" " and !

40.

What will be the output?

name = "Dave"

print ("name")

a)

Dave

b)

"Dave"

c)

name

d)

"name"

41.

#How to you define an empty dictionary called myDict

a)

myDict = " "

b)

myDict = 0

c)

myDict = [ ]

d)

myDict = { }

42.

#Which is the key and value

car = {"Brand" : "BMW"}

a)

Key: Brand. Value: BMW

b)

Key BMW, Value: Brand

c)

{"Brand" : "BMW"}

d)

"Brand" : "BMW"

43.

#Can the keys in a dictionary be the same name?

a)

Yes

b)

No

44.

#What is the output?

a)

3

b)

a,b,c

c)

amt,bull,cow

d)

6

45.

#What is the output?

a)

"A", "B", "C"

b)

"Apple", "Banana","Carrot"

c)

"A": "Apple", "B": "Banana", "C":"Carrot"

d)

Error

46.

#What is the output?

a)

"Apple", "Banana", "Carrot"

b)

"A","B","C"

c)

"A": "Apple", "B": "Banana", "C":"Carrot"

d)

Error

47.

#How to print "Apple"


myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}

a)

print(myDict["A"])

b)

print(myDict[0])

c)

print(myDict{0})

d)

print(myDict{"A"})

48.

#How to add "D": "Doughnut"

myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}

a)

myDict["D"] = "Doughnut"

b)

myDict[3] = "Doughnut"

c)

myDict["D": "Doughnut"]

d)

add myDict[3] "Doughnut"

49.

#How to delete "B": Banana?

myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}

a)

del myDict["B"]

b)

del myDict["B": "Banana"]

c)

del myDict[1]

d)

del myDict{"B"}

50.

#How to replace "B": "Banana" with "B": "Blueberries"

myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}

a)

myDict["B"] = "Blueberries"

b)

myDict["B":"Banana"] = myDict["B":"Blueberries"]

c)

myDict["B"] = myDict["Blueberries"]

d)

None of these

51.

#What will be the output?

a)

Error

b)

{"abc":5}

c)

abc

d)

e

52.

#Print "f"

a)

myList[1][2]

b)

myList[1][1]

c)

myList[2]

d)

myList[0][2]

53.

#What is the output?

a)

12.00

b)

Error

c)

Spicy

d)

Tom Yum

54.

#How to select RANDOM KEY from a Dictionary called "myDict"?

a)

random.shuffle(myDict)

b)

random.choice(myDict)

c)

make a var to store myDict keys using keys() then random choice the var

d)

It is not possible

55.

#What is the output?

a)

CR7

b)

Manchester United

c)

ronaldo

d)

36

56.
What is the word used to describe repetition in programming?
a)
Sequence
b)
Selection
c)
Iteration
d)
Coding
57.
What are the two main types of loops that we have learned about in Python?
a)
IF Function & Variables
b)
FOR and WHILE Loops
c)
Forever and Fixed Loop
d)
Data Types and Numbers
58.
What type of loop is used when you know how many times you want to repeat something?
a)
A WHILE Loop
b)
An IF function
c)
A FOR Loop
d)
A Variable
59.
What type of loop is used when you DO NOT know how many times you want to repeat something?
a)
A WHILE Loop
b)
A Counter
c)
A FOR Loop
d)
A Forever Loop
60.
What would amount equal in this piece of code:

amount = 2 + 5 * 2
a)
12
b)
9
c)
14
d)
5
61.
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
62.
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
63.
What letter will be printed on the screen after running this code:

team = “Manchester United”
letter = name[5]
print(letter)
a)
M
b)
d
c)
e
d)
Nothing prints
64.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
65.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
66.
Look at the code below and identify which of the statements below are true:

for loopCounter in range(10,101,10):
               
     print(loopCounter)
a)
Starts at 10, goes up to 100, increases by 10
b)
Starts at 10, goes upto 101, increases by 10
c)
Starts at 1, goes upto 100, increases by 1
d)
Starts at 10, goes upto 10, increases by 10
67.
What will the following code result in:

name = “Alison”
number = len(name)
print(number)
a)
4
b)
5
c)
6
d)
7
68.
In the following code what will happen if the wrong password is entered:
while password != "computer":
   
    print("Enter Password: ")
 
    p
assword = input()
a)
It will log in
b)
It will keep asking to type in password
69.
What is the position of the name 'Paula' in the following list:
names = ["Paul","Phillip","Paula","Phillipa"]
a)
0
b)
1
c)
2
d)
3
70.
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
71.

Who invented python?

a)

Alaxader Graham Bell

b)

James Gosling

c)

Guido Van Rossum

72.

Is list a mutable data type?

a)

True

b)

False

73.

Which two are a tuple in Python?

a)

(99,100,101)

b)

(11, 33, 77)

c)

[11,22,33]

d)

[2, 4, 6]

74.

Python is a (a)   language.

75.

What will be the output of-

list1 = [51,52,53,54,55]

print (list1)

print (list1[4])

a)

[51, 52, 53, 54, 55]

55

b)

[51, 52, 53, 54, 55]

54

c)

55

d)

Error

76.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

77.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

78.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

79.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

80.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

81.

What would this code do?

a)

Remove the name "Felipe" from the list

b)

Remove the first copy of "John" from the list

c)

Remove the name "Felipe" from the list and print it out to the shell

d)

An error

82.

What would this code show on the screen?

a)

7

b)

6

c)

5

d)

4

e)

An error

83.

What would this code return on the shell?

a)

Nothing

b)

An error

c)

"Woo hoo, you scored!"

d)

"Raheem"

84.

What would this code show in the shell?

a)

3

b)

2

c)

1

d)

0

e)

An error

85.

What would this code show in the shell?

a)

3

b)

2

c)

1

d)

0

e)

An error