wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Chuyên đề 1. Các kiến thức cơ bản_Python

Total questions: 59

Worksheet time: 30mins

Name
Class
Date
1.

Consider the following Python script.

When you click on the file using a Windows file explorer, the script executes but you are unable to see the output. How would you fix that?

a)

b)

c)

d)

D. There is nothing to output

e)

E. None of the above

2.

What is the output of the following code?

a)

A. JamesJamesJamesJamesJamesJames

b)

B. JamesJamesJamesJamesJames

c)

C. JamesJamesJamesJames

d)

D. JamesJamesJames

e)

E. Error: invalid syntax

3.

4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?

a)

A. 15

1

b)

B. 14

1

c)

C. 11

4

d)

D. 15

2

e)

E. 14

2

4.

What is a correct syntax to output "Hello World" in Python?

a)

A. echo("Hello World");

b)

B. p("Hello World")

c)

C. print("Hello World")

d)

D. echo "Hello World"

e)

E. None of the above

5.

What is the value of “Hello”.upper().capitalize()?

a)

A. “Hello”

b)

B. “hello”

c)

C. “HELLO”

d)

D. Runtime Error

e)

E. None of the above

6.

What is the statement evaluates the same to the statement below?

a)

A. print ( 2*27*4)

b)

B. print ( 2*3*4)

c)

C. print ( 2*3**4)

d)

D. print ( 2*3*3*4)

e)

E. None of the above

7.

Which method can be used to replace parts of a string?

a)

A. replaceString()

b)

B. replace()

c)

C. repl()

d)

D. switch()

e)

E. replaceStr()

8.

Which of the following is False?

a)

b)

c)

d)

e)

9.

Which of the following operators has the highest precedence?

a)

A. not

b)

B. &

c)

C. *

d)

D. +

e)

E. -

10.

What is the output of the expression print(-18 // 4)?

a)

A. -4

b)

B. 4

c)

C. -5

d)

D. 5

e)

E. None of the above

11.

Which of the following statements is true?

a)

A. Python is an interpreted language.

b)

B. Python is a high-level programming language.

c)

C. Python is an object-oriented language.

d)

D. All of the above.

e)

E. None of the above

12.

What is output of:

a)

A. foo\bar

baz

b)

B. foo\\barnbaz

c)

C. foo\bar\nbaz

d)

D. foo\\bar\nbaz

e)

E. None of the above

13.

In the Python statement x = a + 5 - b:

a)

A. operators, a statement

b)

B. operands, an expression

c)

C. operands, an equation

d)

D. terms, a group

e)

E. operators, an expression

14.

Which of the following function checks that all characters of a string are in upper case?

a)

A. join(seq)

b)

B. en(string)

c)

C. isupper()

d)

D. ljust(width[, fillchar])

e)

E. None of the above

15.

What will be the output of the following Python code snippet if x = 1?

a)

A. 4

b)

B. 2

c)

C. 1

d)

D. 8

e)

E. 10

16.

Which of the following is correct?

a)

A. Comments are for programmers for better understanding of the program.

b)

B. Python Interpreter ignores comment.

c)

C. You can write multi-line comments in Python using triple quotes, either ''' or """.

d)

D. All of the above

e)

E. None of the above

17.

Consider you import a module (hello) into a Python script (script.py) that you are working

on. Simultaneously you realize that the module is missing a statement, so you update the

module. To make sure your current script imports these new changes in your Python

session, what do you need to do?

a)

A. Import importlib and use reload to import the new changes into the module.

b)

B. The Python interpreter will detect the updates in the module.

c)

C. Import importlib and use reload to import the new changes into the module.

d)

D. Do nothing

e)

E. None of the above

18.

Consider the following code;

After these are executed, what is the value of y?

a)

A. 0

b)

B. 1

c)

C. True

d)

D. False

e)

E. None of the above

19.

What is the output of the print() function call?

a)

A. True

b)

B. False

c)

C. foo

d)

D. bar

e)

E. Syntax Error

20.

What gets printed?

a)

A. Foo

b)

B. foo foo

c)

C. foo 2

d)

D. 2

e)

E. An exception is thrown

21.

What will be the value of x in the following Python expression?

a)

A. 8

b)

B. 4

c)

C. 2

d)

D. 1

e)

E. None of the above

22.

What gets printed assuming the user enters 'foo' at the prompt?

a)

A. f

b)

B. foo

c)

C. Not a number

d)

D. An exception is thrown

e)

E. None of the above

23.

What is the value of the following?

a)

A. 72

b)

B. 72, 101, 108, 108, 111

c)

C. 108

d)

D. 111

e)

E. None of the above

24.

What is the value of code?

a)

A. 1.5

b)

B. 0

c)

C. “12.03-4.5”

d)

D. Runtime Error

e)

E. None of the above

25.
a)

A

b)

B

c)

C

d)

D

e)

E

26.

Consider the following code,

a)

A. True

b)

B. False

c)

C. Undetermined

d)

D. Runtime Error

e)

E. None of the above

27.

Which of the following is not a built-in function?

a)

A. ord()

b)

B. hasattr()

c)

C. callable()

d)

D. nullable()

e)

E. None of the above

28.

Which of the following is False?

a)

A

b)

B

c)

C

d)

D

29.

a)

A

b)

B

c)

C

d)

D

e)

E

30.

Python language was developed in what year?

a)

A. 1985

b)

B. 1820

c)

C. 1991

d)

D. 2001

e)

E. 1979

31.

What is a statement in programming?

a)

A. Expresses an action to be carried out

b)

B. Always returns results like expressions

c)

C. Rules controlling how components in a program are combined

d)

D. An instruction to perform a task, usually one word

e)

E. None of the above

32.

What is the output of the following code?

a)

A. James

b)

B. JamesJamesJamesJamesJamesJames

c)

C. JamesJamesJamesJamesJames

d)

D. Error: invalid syntax

e)

E. None of the above

33.

What output will the console show, if 15 and 30 are entered by the user?

a)

A. Syntax error

b)

B. The concatenation of the two numbers 1530

c)

C. The sum of the two numbers 45

d)

D. Compiler error

e)

E. None of the above

34.

What is the data type of print(type(0xFF))

a)

A. number

b)

B. hexint

c)

C. hex

d)

D. int

e)

E. float

35.

Which is the better statement if x+=1 is removed?

a)

A. There is no difference

b)

B. The loop is infinite

c)

C. The print function is stopped

d)

D. The output equals to 10

e)

E. None of the above

36.

Refer to the following code, which of the following statement is correct?

a)

A. The code doesn’t have errors

b)

B. The code shows unidentified syntax (semicolon)

c)

C. Integer cannot add with float

d)

D. The expression a + b does not have a left hand side operator

e)

E. None of the above

37.

What is the value of code?

a)

A

b)

B

c)

C

d)

D

e)

E

38.
a)

A

b)

B

c)

C

d)

D

e)

E

39.
a)

A

b)

B

c)

C

d)

D

e)

E

40.
a)

A

b)

B

c)

C

d)

D

e)

E

41.
a)

A

b)

B

c)

C

d)

D

e)

E

42.
a)

A

b)

B

c)

C

d)

D

43.
a)

A

b)

B

c)

C

d)

D

44.
a)

A

b)

B

c)

C

d)

D

45.
a)

A

b)

B

c)

C

d)

D

46.

Which method can be used to remove any whitespace from both the beginning and the

end of a string?

a)

A. ptrim()

b)

B. trim()

c)

C. len()

d)

D. strip()

e)

E. None of the above

47.
a)

A

b)

B

c)

C

d)

D

e)

E

48.
a)

A

b)

B

c)

C

d)

D

e)

E

49.
a)

A

b)

B

c)

C

d)

D

e)

E

50.
a)

A

b)

B

c)

C

d)

D

e)

E

51.
a)

A

b)

B

c)

C

d)

D

e)

E

52.
a)

A

b)

B

c)

C

d)

D

e)

E

53.
a)

A

b)

B

c)

C

d)

D

e)

E

54.
a)

A

b)

B

c)

C

d)

D

e)

E

55.
a)

A

b)

B

c)

C

d)

D

e)

E

56.
a)

A

b)

B

c)

C

d)

D

e)

E

57.
a)

A

b)

B

c)

C

d)

D

e)

E

58.
a)

A

b)

B

c)

C

d)

D

e)

E

59.
a)

A

b)

B

c)

C

d)

D

e)

E