wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python workshop day2

Total questions: 20

Worksheet time: 7mins

Name
Class
Date
1.

What operator checks if two values are equal?

a)

==

b)

!=

c)

>

d)

<

2.

The if statement is used for:

a)

Looping through a sequence

b)

Defining functions

c)

Checking conditions and executing code based on the result

d)

Storing data

3.

How can you write an if statement that checks if a number is greater than 10?

a)

if num > 10:

b)

num > 10

c)

if(num > 10)

d)

greaterThanTen(num)

4.

Python is a case-sensitive programming language

a)

True

b)

False

5.

What is the purpose of defining a function?

a)

To create a reusable block of code

b)

To store data permanently

c)

To define data types

d)

To control the flow of the program

6.

When calling a function, how do you pass arguments (values) to it?

a)

Place them within parentheses after the function name

b)

Use keywords to identify them

c)

Both a and b are correct

d)

Arguments are automatically assigned

7.

If a function expects two arguments, what happens if you only provide one when calling it?

a)

The function will behave unexpectedly

b)

The function will ignore the extra argument

c)

An error will occur

d)

None of the above

8.

How can you represent the boolean value True in Python?

a)

'True'

b)

true

c)

True

d)

0

9.

numbers = [1, 2, 3, 4]

print(numbers[2:4])

a)

[1, 2]

b)

[3, 4]

c)

Error

d)

None

10.

How can you check the data type of a variable in Python?

a)

checkType(var)

b)

typeof var

c)

type(var)

d)

dataType var

11.

How can you iterate through the characters of a string using a loop?

a)
  • for char in string:

b)

loopThroughString(string)

c)

string.loop(print(char))

d)

There is no built-in way to loop through characters in Python.

12.

x = 3

y = 2

print(x // y)

a)

1

b)

1.5

c)

Error

d)

None

13.

Which of the following CANNOT be directly stored in a variable in Python?

a)

Integer

b)

Float

c)

List

d)

Function

14.

x = 5
y = x
x = 10
print(y)

a)

5

b)

10

c)

Error

d)

None

15.

name = "Alice"
greeting = "Hello, " + name + "!"
print(greeting)

a)

Hello, name!

b)

Hello, Alice!

c)

Error

d)

None

16.

What is the purpose of the range() function in loops?

a)
  • To define a counter variable

b)
  • To create a sequence of numbers for iteration

c)

To modify existing lists

d)

To break out of a loop

17.

How can you return a value from a function?

a)

Use the return keyword followed by the value.

b)

Functions inherently return the last evaluated expression.

c)
  • Store the value in a global variable within the function.

d)

Printing the value inside the function automatically returns it

18.

age = 20

is_adult = age >= 18

print(is_adult)

a)

True

b)

False

c)

Error

d)

None

19.

my_tuple = (1, 2, 3)

my_tuple = my_tuple + (4,)

print(my_tuple)

a)

(1, 2, 3)

b)

(1, 2, 3, 4)

c)

Error

d)

None

20.

fruits = ["apple", "banana", "orange"]
print(fruits[1])

a)

"apple"

b)

"banana"

c)

Error

d)

None