wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week2

Total questions: 8

Worksheet time: 5mins

Name
Class
Date
1.

3 + 4 * 2 // (1 - 5) ** 2

a)

2

b)

2.5

c)

3

d)

3.5

2.

Reorder the following to get an output of 7

print(result)

x *= 2

x += 5

result = x // 3

x -= 3

a)

x *= 2

x = 10

x -= 3

x += 5

result = x // 3

print(result)

b)

x = 10

x -= 3

x *= 2

x += 5

result = x // 3

print(result)

c)

x = 10

x += 5

x *= 2

x -= 3

result = x // 3

print(result)

d)

x = 10

x *= 2

x -= 3

x += 5

result = x // 3

print(result)

3.

After the following statements, what are the values of x and y?

x = 15

y = x

x = 22

a)

x is 15 and y is 15

b)

x is 22 and y is 22

c)

x is 15 and y is 22

d)

x is 22 and y is 15

4.

Given the following variable names, identify which ones are invalid?

a)

var$ible

b)

_privatevar

c)

2nd_variable

d)

valid variable

5.

print(2**3**2)

(a)  

6.

3 * str(2)+"simr"

(a)  

7.

Given this function:
def greet(name, greeting="Hello"):

return f"{greeting}, {name}!"

Match the correct function calling with their output

a)

print(greet())

1.

Error!

b)

print(greet("Alice", "Hi"))

2.

Hi, Alice!

c)

print(greet("Bob"))

3.

Hello, Bob!

d)

print(greet)

4.

<function greet at x>

8.

def factorial(n):

if n == 1:

return 1

else:

return n * factorial(n - 1)

# Compute the factorial of 0

print(factorial(0))

a)

Error

b)

NAN

c)

1

d)

0