wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Programming

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is an iterator in Python?

a)

A container that can hold multiple values

b)

An object that can be iterated upon

c)

A variable that holds a single value

d)

A function that takes an iterable as input

2.

Which of the following is an example of an iterable in Python?

a)

List

b)

Integer

c)

String

d)

All of the mention

3.

What is the purpose of the 'print()' function in Python?

a)

To read user input from the keyboard.

b)

To write text to the console.

c)

To format strings using placeholders.

d)

To perform mathematical calculations.

4.

Which of the following will produce an error when used as an argument to the 'print()' function?

a)

5

b)

"Hello"

c)

[1, 2, 3]

d)

{"key": "value"}

5.

What is the syntax for printing a variable 'x' using the 'print()' function?

a)

print x

b)

print(x)

c)

print("x")

d)

print"x"

6.

How do you include a newline character in a 'print()' statement?

a)

Use the '\n' escape sequence.

b)

Use the ';' character.

c)

Use the '+' operator.

d)

Use the '*' operator.

7.

What does the 'print()' function do in Python?

a)

Display the contents of a file on the screen

b)

Print a message to the console

c)

Return the value of an expression

d)

Open a new command prompt

8.

Which of the following is a valid way to print the string "Hello, World!" using the 'print()' function?

a)

print "Hello, World!"

b)

print ("Hello, World!")

c)

Print ("Hello, World!")

d)

PRINT "Hello, World!"

9.

What is the output of the following code?

a)

x = 3 and y = 5

b)

x = 3, y = 5

c)

x = 3; y = 5

d)

x, y = 3, 5

10.

What is the output of the following code?

a)

5

b)

"5"

c)

x+y

d)

Error

11.

Which of the following is a valid way to print the values of multiple variables using the 'print()' function?

a)

print(x, y, z)

b)

print(x; y; z)

c)

print(x + y + z)

d)

print(x y z)

12.

What is the output of the following code: print("apple", "banana", "orange", sep=", ")

a)

"apple banana orange"

b)

"apple, banana, orange"

c)

"apple,banana,orange"

d)

"apple , banana , orange"

13.

What is the purpose of the 'sep' parameter in the 'print()' function?

a)

It specifies the character to use between separate print arguments

b)

It specifies the number of spaces between separate print arguments

c)

It specifies the color of the text to be printed

d)

It specifies the type of file to be printed to

14.

What is the purpose of the 'end' parameter in the print() function?

a)

It specifies the character to use between separate print arguments

b)

It specifies the number of spaces between separate print arguments

c)

It specifies the color of the text to be printed

d)

It specifies the character to print at the end of the output

15.

What is the correct syntax for creating an empty list in Python?

a)

[]

b)

[0]

c)

()

d)

{}

16.

Which of the following is NOT a valid method to add an element to a list in Python?

a)

append()

b)

insert()

c)

add()

d)

extend()

17.

Which of the following is the correct way to access the first element of a list in Python?

a)

list[1]

b)

list[0]

c)

list.first()

d)

list.pop()

18.

What is the result of the following code:

numbers = [1, 2, 3, 4]

print(numbers[1:3])

a)

[1, 2]

b)

[2, 3]

c)

[2, 3, 4]

d)

[1, 2, 3]

19.

What is the result of the following code:

name = input("What is your name? ")

print("Hello, " + name + "!")

a)

The code will not run because it contains a syntax error

b)

The code will run, but no output will be produced

c)

The code will run and output the string "Hello, World!"

d)

The code will run and output the string "Hello, " followed by the user's name input

20.

What is the output of the following code snippet?

a)

[1, 5, 3, 4]

b)

[5, 2, 3, 4]

c)

[1, 5, 3]

d)

[1, 5, 3, 5]

21.

What is the output of the following code snippet?

a)

[1, 2, 3, 4]

b)

[1, 3, 4]

c)

[2, 3, 4]

d)

[1, 2, 4]

22.

What is the output of the following code snippet?

a)

[2, 4, 6]

b)

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

c)

[1, 2, 3, 2, 4, 6]

d)

[1, 4, 9]

23.

How to comment a single line in python?

a)

!

b)

#

c)

'''

d)

()

24.

How to comment multiple line in python?

a)

''' '''

b)

{ }

c)

[ ]

d)

# #

25.

What will be the output of the following code?

x = Input ("Please do not continue, enter the number to cycle")

print (x)

a)

number enter by user

b)

NameError

c)

Please do not continue

d)

x