wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

failure

Total questions: 61

Worksheet time: 33mins

Name
Class
Date
1.

The number of arguments that can be passed to a function is

a)

1

b)

1 or more

c)

0

d)

0 or more

2.

The two types of functions used in Pythons are

a)

System function

b)

User function and system call

c)

Builts-in and user-defined         

d)

Custom function and user function

3.

The variable defined outside the function is referred as

a)

automatic        

b)

register

c)

global

d)

static

4.

The default arguments specified in the function header is an

a)

Identifier followed by an #

b)

Identifier followed by the default value within back-ticks

c)

Identifier followed by the default value within []

d)

Identifier followed by an = and the default value

5.

Explain the output of the following program

Pi = 3.14

Def tt_hinh_non(bk =10, h = 10):

            Print(pi*bk*bk*k)

Print(tt_hinh_non(5,5))

a)

a.      The variable pi is placed outside the function

b)

a.      The arguments are not the same as the default parameter

c)

a.      Two nested print() statements

d)

a.      The function don’t have a return statement

6.

Guess the value of x with the below code:

Import math

X = math.sqrt(36)

a)

6.0

b)

6

c)

-6

d)

error

7.

A local variable in Python is a variable that is

a)

Defined inside every function

b)

Local to the given program

c)

Accessible from within the function

d)

All of these

8.

Which of the following logical operations are used in a while loop?

a)

True, False

b)

and, or, but

c)

and, neither, nor           

d)

and, or, not

9.

When running the program, if the user enters 2003 and 2023 respectively, what  is the last line in the program execution result?

Def tinh_tuoi(ns, nht):

            Tuoi = nht – ns

            Print (f”{nht} – {ns} =”)

            Print((tuoi)

Nam_sinh = int(input())

Nam_hien_tai = int(input())

Print(tinh_tuoi(nam_sinh, nam_hien_tai)

a)

None

b)

2023

c)

20

d)

a.      2023 -2020 =

10.

Corresponding to the function call. Print (KQ(TD(7.5, 6.5, 8.5, 1, 1 2)))

Def  TD(t, v, c, s1 = 1, s2 = 1, s3 = 1):

            Return t*s1 + v*s2 +c*s3

Def  KQ(d):

            If d >= 24:

                        Return “Học bổng”

            Elif d >= 20:

                        Reuturn “Đỗ”

            Else:

                        Return “Trượt”

a)

Học bổng

b)

Đỗ

c)

Trượt

d)

31.0

11.

Which statement is correct about the while loop in Python?

a)

You cannot have a while loop nested within another while loop

b)

The condition in while cannot have logical operations and/or/not

c)

Repeatedly execute a block of statements while a condition is true

d)

In the while loop, the break statement can be used

12.

Which statement is correct about using for loop in Python?

a)

Only use maximum of 2 nested for loops.

b)

Cannot use continue or break statements in a for loop

c)

for is used when a block of code needs to be executed repeatedly a known number of times

d)

for is used when a block of code needs to be executed repeatedly an indenfinite number of times until a condition is met.

13.

Guess the output of the following code if call quad(3):

Def quad(x):

            X *=x

            X *=x

a)

81

b)

3

c)

9

d)

27

14.

Guess the program as shown below. Where, the variable count is used to count pairs (i,j) with the same parity. Which conditional expression is correct to put in the yellow highlighted area in the statement at line

1          count = 0

2          for i in range (10):

3                      for j in range(10):

4                                  if ________

5                                              count +=1

6          print(count)

a)

(i % 2 == 0) and (j % 2 == 0)

b)

(i+j) % 2 == 0

c)

(i+j) % 2 != 0

d)

(i % 2 != 0) and (j % 2 != 0)

15.

Which conditional expression of the if statement needs to be filled in the blank part in line 5?

1          count = 0

2          n = 20

3          for num in range(2,n):

4                      for i in range(2, int(num/2)+1):

5                                  if _______________:

6                      else:

7                                  count +=1

8          print(count)

a)

num % 2 == 0

b)

num %i ==0

c)

num%i !=0

d)

num % 2 != 0

16.

Given the program as shown in the following figure. Which option fills in the blank on the line 4 so that the program does not loop infinitely (choose 2 answers):

X = 1

While x < 10:

            Print(x)

            X ______

a)

*=2

b)

/=2

c)

-=2

d)

+=2

17.

determine the distance between two adjacent values in a list 

(a)  

18.

All values generated in the list must be less than

(a)  

19.

Initial value of the list  

(a)  

20.

Rearrange the statements below to form a complete program that calculates the sum of odd numbers form 1 to n.

1. for i in range(1, n+1)

2. n = int(input(“Nhap vao mot so:”)

3. s+=i

4. s= 0

5. print(f’s={s}’)

6. if (i%2==1):

a)

2 4 1 3 6 5

b)

2 4 1 6 3 5

c)

4 2 1 3 6 5

d)

4 2 3 1 5 6

21.

what is the output displayes on the screen when the following program is executed?

For num in range(10,14):

            For i in range(2, num):

                        If num%i==0:

                                    Print(num, end = “ “)

                                    Break

a)

10 12   

b)

Nothing on the screen

c)

10 11 12 13      

d)

10 11 12 13 14

22.

What is the value of variable x after executing the following program?

X= 0

For i in range (10):

            For j in range (-1,-10,-1):

                        X+=1

a)

100

b)

90

c)

99

d)

101

23.

The function divmod(10,20) is evaluated as

a)

(10//20, 10%20)

b)

(10/20, 10%20)

c)

(10%20, 10//20)

d)

(10//20,10*20)

24.

Assume the list superstore is [1,2,3,4,5] which of the following is correct syntax for slicing operation?

a)

print(superstore[0:])

b)

print(superstore[:2])

c)

print(superstore[:-2])

d)

All of these

25.

The list function that inserts the item at the given index after shifting the items to the right is

a)

append()

b)

insert()

c)

sort()

d)

index()

26.

What will be the output of the following?

a)

1

b)

4

c)

2

d)

5

27.

There is a list A = [1,3,5,7,9,11], which of the following syntax is the best correct to get a sublist

a)

A[1:-2]

b)

A[1:3]

c)

A[1:]

d)

All of these

28.

Suppose continents = [1,2,3,4,5], what is the output of len(continents)?

a)

4

b)

5

c)

error

d)

none

29.

To insert the string “snake” to the third position in list zoo, which of the following statement is used?

a)

zoo.insert(2, “snake”)

b)

zoo.append(3, “snake”)

c)

zoo.insert(3, "snake”)   

d)

zoo.add(3, “snake”)

30.

The method that is used to count the number of times an item has occurred in the list is

a)

len()

b)

count()

c)

extend()

d)

length()

31.

Find the output of the following code:

a)

33

b)

3

c)

6

d)

5

32.

. Assume quantity = [3,4,5,20, 5, 25,1,3] then what will be the items of quantity list after quantity.pop(1)

a)

[3,4,5,20,5,25,1,3]

b)

[3,5,20,5,25,1,3]

c)

[1,3,3,4,5,5,20, 25]

d)

[1,3,4,5,20,5,25]

33.

What is the correct way to define a function in Python?

a)

def function_name:

b)

function function_name():

c)

def function_name():

d)

define function_name():

34.

Which of the following is NOT a built-in data type in Python?

a)

List

b)

Dictionary

c)

Tuple

d)

Tree

35.

How can you remove an element from a list in Python?

a)

remove()

b)

del()

c)

pop()

d)

all of the above

36.

What is the default return value of a function that does not have a return statement?

a)

0

b)

None

c)

False

d)

" "(empty string)

37.

What will print("Hello"[::-1]) output?

a)

Hello

b)

olleH

c)

H e l l o

d)

SyntaxError

38.

Which of the following methods can be used to check if a key exists in a dictionary?

a)

key in dict

b)

dict.has_key(key)

c)

dict.contains(key)

d)

exists(dict, key)

39.

What will print(bool([])) output?

a)

True

b)

False

c)

None

d)

[]

40.

What will print(type(5.0)) output?

a)

<class 'int'>

b)

<class 'float'>

c)

<class 'double'>

d)

<class 'number'>

41.

output?

def test(x, y=[]):

    y.append(x)

    return y

print(test(1))

print(test(2))

a)

[1], [2]

b)

[1], [1, 2]

c)

[1, 2], [1, 2]

d)

[1, 2], [2]

42.

output:

print("Python"[2:5])

a)

tho

b)

yth

c)

tho

d)

tho

43.

def func(a, b=10):

    return a + b

print(func(5))

a)

5

b)

10

c)

15

d)

Error

44.

What does print(list(range(3, 10, 2))) output?

a)

[3, 4, 5, 6, 7, 8, 9]

b)

[3, 5, 7, 9]

c)

[3, 6, 9]

d)

[3, 10]

45.

s = "abcdef"

print(s[:4] + s[4:])

a)

abcd ef

b)

abcdef

c)

abcd

d)

Error

46.

What will print("hello".capitalize()) output?

a)

hello

b)

Hello

c)

HELLO

d)

hELLO

47.

What will print("A B C".split()) output?

a)

['A', 'B', 'C']

b)

['A B C']

c)

['A', ' B', ' C']

d)

['A', '', 'B', '', 'C']

48.

. What does the following code output?

def f(x=[]):

    x.append(1)

    return x

print(f())

print(f())

a)

[1] [1]

b)

[1] [1, 1]

c)

[1, 1] [1]

d)

[1, 1] [1, 1]

49.

What is the correct syntax for an if-else statement in Python?

a)

if condition { } else { }

b)

if condition: else:

c)

if condition: ... elif condition: ... else:

d)

if condition then ... else then ...

50.

x = 10

if x > 5:

    print("A")

elif x > 8:

    print("B")

else:

    print("C")

a)

A

b)

B

c)

C

d)

No output

51.

Which statement about Python loops is true?

a)

for loops require a predefined number of iterations

b)

while loops always execute at least once

c)

break exits the loop but continue stops the program

d)

Python does not support for loops

52.

What does the else clause in a while loop do?

a)

Executes only if the loop is broken with break

b)

Executes if the loop runs at least once

c)

Executes if the loop condition becomes False naturally

d)

Executes before the loop starts

53.

. What will for i in "hello": print(i) output?

a)

h e l l o

b)

hello

c)

h on one line, then e, then l, etc.

d)

olleh

54.

Which of the following is NOT a valid way to iterate through a string?

a)

for char in "hello": print(char)

b)

for i in range(len("hello")): print("hello"[i])

c)

while "hello": print("loop")

d)

"hello".split() and iterating through the list

55.

What does range(3, 10, 2) produce?

a)

[3, 4, 5, 6, 7, 8, 9]

b)

[3, 5, 7, 9]

c)

[3, 6, 9]

d)

. [3, 10]

56.

What will print("hello".replace('l', 'L', 1)) output?

a)

heLLo

b)

heLlo

c)

heLLo

d)

Error

57.

def mystery(n):

    if n == 1:

        return 1

    else:

        return n * mystery(n - 1)

print(mystery(4))

a)

10

b)

24

c)

15

d)

12

58.

. x = 5

if x == 5 and not (x > 10 or x < 3):

    print("A")

elif x < 10:

    print("B")

else:

    print("C")

a)

A

b)

B

c)

C

d)

A B

59.

How many times will the while loop execute

x = 0

while x < 10:

    x += 2

print("Done")

a)

10 times

b)

5 times

c)

infinite times

d)

6 times

60.

What is the final value of count after execution?

count = 0

for i in range(4):

    for j in range(i):

        count += 1

print(count)

a)

4

b)

6

c)

3

d)

5

61.

for i in range(10, 0, -3):

    print(i, end=" ")

a)

10 7 4

b)

10 8 6 4 2

c)

10 9 8 7 6 5 4 3 2 1

d)

10 7 4 1