Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2K views

Python Modules Summary Test

This document contains a 20 question multiple choice test on Python programming concepts. The test covers topics like data types, variables, operators, conditional and loop statements, functions, modules and packages. For each question there are 4 potential answer choices to select from.

Uploaded by

Arn Arn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Python Modules Summary Test

This document contains a 20 question multiple choice test on Python programming concepts. The test covers topics like data types, variables, operators, conditional and loop statements, functions, modules and packages. For each question there are 4 potential answer choices to select from.

Uploaded by

Arn Arn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Module 1 Test

1. What do you call a file containing a program written in a high-level programming language?
a. A source file
b. A target file
c. A machine file
d. A code file

2. What is the expected behavior of the following program? print("Hello!")


a. The program will output "Hello !" to the screen
b. The program will generate an error message on the screen
c. The program will output ("Hello!") to the screen
d. The program will output Hello! to the screen

3. What is a machine code?


a. A low-level programming language consisting of the binary digits/bins that the computer
reads and understands
b. A medium-level programming language consisting of the assembly code designed for the
computer processor
c. A low-level programming language consisting of hexadecimal digits that make up high-level
language instructions
d. A high-level programming language consisting of instruction list that humans can read and
understand

4. What is the expected behavior of the following program? prin("Goodbye!")


a. The program will output "Goodbye!"
b. The program will generate an error message on the screen
c. The program will output ("Goodbye!")
d. The program will output Goodbye! to the screen

5. What is the best definition of a script?


a. It's a text file that contains instructions which make up a Python program
b. It's an error message generated by the compiler
c. It's an error message generated by the interpreter
d. It's the text file that contains sequences of zeroes and ones

6. Select the true statements? (Select two answers)


a. Python 3 is backwards compatible with Python 2
b. Python is a good choice for creating and executing tests for applications
c. Python is free, open-source, and multiplatform
d. Python is a good choice for low-level programming, e.g. when you want to implement an
effective driver
7. What are the four fundamentals elements that make a language?
a. An alphabet, morphology, phonetics, and semantics
b. An alphabet, a lexis, phonetics, and semantics
c. An alphabet, phonetics, phonology, and semantics
d. An alphabet, a lexis, a syntax, and semantics
8. What is true about compilation? (Select two answers)
a. Both you and the end user must have the compiler to run your code
b. It tends to be faster than the interpretation
c. The code is converted directly into the machine code executed by the processor
d. It tends to be slower than the interpretation
9. What do you call a command-line interpreter which lets you interact with your OS and execute
Python commands and scripts?
a. A console
b. An editor
c. A compiler
d. Jython

10. What is CPython?


a. It's the default, reference implementation of Python, written in the C language
b. It's the default, reference implementation of the C language, written in Python
c. It's a programming language that is a superset of Python, designed to produce C-like
performance with code written in Python
d. It's a programming language that is a superset of the C language, designed to produce
Python-like performance with code written in C
Module 2 –Test

1. What is the output of the following snippet if the user enters two lines containing 2 and 4
respectively?

a. the code will cause a runtime error

b. 8.0

c. 4.0

d. 2.0

2. What is the output of the following snippet if the user enters two lines containing 2 and 4
respectively?

a. 6

b. 2

c. 24

d. 4

3. What is the output of the following snippet if the user enters two lines containing 2 and 4
respectively?

a. 24

b. 2

c. 4

d. 6

4. What is the output of the following snippet?

a. 8

b. 17

c. 17.5

d. 8.5
5. What is the output of the following snippet if the user enters two lines containing 11 and 4
respectively?

a. 2

b. 4

c. 1

d. 3

6. What is the output of the following snippet?

a. 1 2

b. 1 1

c. 2 1

d. 2 2

7. What is the output of the following snippet if the user enters two lines containing 3 and 6
respectively?

a. 18

b. 666

c. 333333

d. 36
8. Left-sided binding determines that the result of the following expression:

a. 4.5

b. 0.0

c. 0

d. 0.166666666666666

9. The ** operator:

a. does not exist

b. performs exponentiation

c. performs floating point multiplication

d. performs duplicated multiplication

10. The result of the following division:

a. cannot be evaluated

b. is equal to 1.0

c.is equal to 1

d. cannot be predicted

11. The print() function can output values of:

a. just one argument

b. any number of arguments (including zero)

c. not more than five arguments

d. any numbers of arguments (excluding zero)

12. What is the output of the following snippet if the user enters two lines containing 2 and 4
respectively?

a. 4.0

b. 8.0

c. 2.0

d. The code will cause a runtime error


13. What is the output of the following snippet?

a. 1 1 1

b. 1 * 1 * 1

c. x*y*z

d. x y z

14. The meaning of the keyword parameter is determined by:

a. its value

b. the position within the argument list

c. its connection with existing variables

d. the argument’s name specified along with its value

15. Which of the following are true (Select two answers)

a. addition precedes multiplication

b. The ** operator uses right-sided binding

c. The right argument of the % operator cannot be zero

d. The result of the / operator is always an integer value

16. The \n digraph forces the print() function to:

a. stops its execution

b. output exactly two characters: \ and n

c. duplicate the character next to the digraph

d. break the output line

17. Which of the following variable names are illegal? (Select two answers)

a. true

b. True

c. TRUE

d. and

18. What is the output of the following snippet?

a. 17

b. 25

c. the snippet will cause an execution error

d. 17.0
19. The value twenty point twelve times ten raised to the power of eight should be written as:

a. 20E12.8

b. 20.12E8

c. 20.12*10^8

d.20.12E8.0

20. The 0o prefix means that the number after it is denoted as:

a. hexadecimal

b. decimal

c. octal

d.binary
Module 3- Test

1. What is the output of the following snippet?

a. [1, 2, 3, 3, 2, 1]
b. [1, 1, 1, 1, 2, 3]
c. [1, 2, 3, 1, 2, 3]
d. [3, 2, 1, 1, 2, 3]

2. What is the output of the following snippet?

a. 0
b. 2
c. the snippet will cause a runtime error
d. 1

3. What is the output of the following snippet?

a. 7
b. 02
c. 4
d. 6

4. How many hashes (#) will the following snippet send to the console?

a. zero
b. two
c. three
d. one

5. An operator able to check whether two values are equal is coded as:

a. ==
b. !=
c. ===
d. =
6. What value will be assigned to the x variable?

a. 1
b. 0
c. True
d. False

7. What is the output of the following snippet?

a. 1
b. 0
c. 2
d. 3

8. The second assignment:

a. doesn't change the list


b. shortens the list
c. extends the list
d. reverses the list

9. After the execution of the following snippet, the sum of all vals elements will be equal to:

a. 5
b. 4
c. 2
d. 3
10. What is the output of the following snippet?

a. [2, 3, 4]
b. [2, 3]
c. [2]
d. []

11. How many stars (*) will the following snippet send to the console?

a. one
b. three
c. zero
d. two

12. Which of the following sentences are true? (Select two answers)

a. vals is longer than nums


b. nums and vals are two different lists
c. nums is longer than vals
d. nums and vals are of the same length

13. Take a look at the snippet, and choose the true statements. (Select two answers)

a. nums and vals are of the same length


b. nums is replicated and assigned to vals
c. nums is longer than vals
d. nums and vals refer to the same list

14. How many hashes (#) will the following snippet send to the console?

a. zero
b. two
c. one
d. Three
15. How many stars (*) will the following snippet send to the console?

a. zero
b. two
c. three
d. one

16. What is the output of the following snippet?

a. [3, 2, 1]
b. [3, 3, 3]
c. [1, 1, 1]
d. [1, 2, 3]

17. How many elements does the my_list list contain?

a. four
b. one
c. three
d. two

18. What is the output of the following snippet?

a. 1
b. -2
c. -1
d. 3

19. How many hashes (#) will the following snippet send to the console?

a. eight
b. two
c. one
d. four
20. The value eventually assigned to x is equal to:

a. 1
b. False
c. True
d. 0
Module 4 – Test

1. The following snippet:

a. will output 4
b. will output 2
c. will return None
d. is erroneous
2. What is the output of the following snippet?

a. the code will cause a runtime error

b. 2

c. None

d. 4

3. The fact that tuples belong to sequence type means that:


a. they can be indexed and sliced like lists
b. they are actually lists
c. they can be extended using the .append( ) method
d. they can be modified using the del instruction

4. What is the output of the following snippet?

a. 3
b. the code is erroneous
c. 1
d. 6
5. What is the output of the following snippet?

a. (2,1)

b. (2)

c. 2

d. the snippet is erroneous

6. What is the output of the following snippet?

a. 2
b. 6
c. the snippet is erroneous
d. 4

7. A built-in function is a function which:


a. is hidden from programmers
b. comes with Python, and is an integral part of Python
c. has to be imported before use
d. has been placed within your code by another programmer

8. Which of the following lines property starts a function using two parameters, both with zeroed
default values?

a. def fun (a=b=c):

b. def fun (a=0, b=0):

c. fun fun(a, b= 0):

d. fun fun(a=0,b):

9. A function defined in the following way. (Select two answers)

a. must be invoked with exactly one argument

B. may be invoked with exactly one argument

c. may be invoked without any argument

d. must be invoked without any argument


10. What is the output of the following snippet?

a. 2

b. None

c. the code will cause a runtime error

d. 1

11. The following snippet:

a. is erroneous

b. will output 2

c. will output 16

d. will output 4

12. What is the output of the following snippet?

a. 3

b. 0

c. 9

d. the snippet is erroneous

13. What is the output of the following snippet?

Ans: no output the snippet is erroneous


14. What is the output of the following snippet?

a. 22

b. 11

c. 21

d. 12

15. What code would you insert instead of the comment to obtain the expected output?

Expected output:

Code:

Ans: print(k[0])

16. Which of the following statements are true? (Select two answers)

a. The None value cannot be used outside functions

b. The None value can be compared with variables

c. The None value can be assigned to variables

d. The Non value can be used as an argument of arithmetic operators

17. Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means
that the following instructions:

a. is fully correct

b. is illegal

c. may be illegal of the tuple contains strings

d. can be executed if and only if the tuple contains at least two elements
18. What is the output of the following snippet?

a. {‘one’, ‘two’, ‘three’}

b. two

c. one

d. three

19. What is the output of the following snippet?

a. the code is erroneous

b. 3

c. 4

d. 6

20 . Which of the following lines properly starts a parameterless function definition?

a. fun function( ):

b. def fun():

c.def fun:

d. function fun( ):
Part 1 Summary Test

1. How many elements does the lst list contain?

a. two

b. zero

c.one

d. three

2. What is the output of the following snippet?

a. 2

b. 0

c.1

d. the snippet will cause a runtime error

3. What is the output of the following piece of code if the user enters two lines containing 3 and 2
respectively?

a. 1

b. 0

c.3

d. 2
4. What is the output of the following piece of code if the users enter two lines containing 2 and 4
respectively?

a. 4.0

b. 1.0

C.0.0

d. 2.0

5. What is the output of the following snippet?

a. 4

b. 6

C.2

d. the snippet is erroneous and will cause SyntaxError

6. What will be the output of the following snippet?

a. 1 1

b. 0 1

C.0 0

d. 1 0

7. What will be the output of the following snippet?

a. 4

b. 44

C.(4)

d. (4,)
8. Which of the following sentences are true about the code? (Select two answers)

a. nums has the same length as vals

b. nums and vals are different lists

c. vals is longer than nums

d. nums and vals are different names of the same list

9. What value will be assigned to the x variable?

a. True

b. False

C. 0

d. 1

10. What is the output of the following piece of code?

a. 1 1 2

b. 1 2 1

c. 2 1 2

d. 1 2 2
11. Take a look at the snippet and choose the true statement:

a. the snippet will cause a runtime error

b. nums and vals have the same length

c. vals is longer than nums

d. nums is longer than vals

12. Which of the following variable names are illegal and will cause the SyntaxError exception?
(Select two answers)

a. print

b. In

c. for

d. in

13. Assuming that my_tuple is correctly created tuple, the fact that tuples are immutable means
that the following instruction:

a. is fully correct

b. can be executed if and only if the tuple contains at least two elements

c. is illegal

d. may be illegal if the tuple contains strings

14. What is the output of the following snippet?

a. [1, 4, 9, 16]

b. [0, 1,9,16]

c. [0,1,4,16]

d. [0,1,4,9]
15. Which of the following lines correctly invoke the function defined below? (Select two answers)

a. fun ( 0, 1, 2)

b. fun ( b =1)

c. fun()

d. fun (b = 0, a = 0)

16. What is the output of the following snippet?

a. 1

b. the code will cause a runtime error

c. 2None

d. 2

17. What is the output of the following piece of code?

a. 0.0

b. 0.4

c. 0.2

d.0

18. The result of the following

a. be predicted

b. is equal to 0.5

c. is equal to 0

D. is equal to 0.0
19. The following snippet:

a. will output 4

b. will output 2

c. will output 0

d. is erroneous

20. How many stars ( *) will the following snippet send to the console?

a. two

b. zero

c. the snippet will enter an infinite loop, printing one star per line

d. one

21. What is the output of the following piece of code?

a. asepbsepc

b. asepbsepcsep

c. a b c

d. abc

22. How many hashes ( # ) will the following snippet send to the console?

a. zero

b. three

c. nine

d. Six
23. An operator able to check whether two values are not equal is coded as:

a. <>

b. !=

c. not ==

d.=/=

24. The meaning of positional argument is determined by:

a. its value

b. the arguments name specified along with its value

c. its position within the argument list

d. its connection with existing variables

25. What is the output of the following piece of code if the user enters two lines containing 3 and 6
respectively?

a. 6

b. 36

c. 3

d. 63

26. What is the output of the following snippet?

a. [1,2,2,2]

b. [1,1,1,2]

c. [2,1,1,2]

d.[1,2,1,2]
27. What is the output of the following snippet?

a. (‘one’,’two’,’three’)

b. one

c. three

d.two

28. What is the output of the following snippet?

a. 0 1

b. the code is erroneous (the dict object has no vals() method)

c.1 0

d.0 0

29. What is the output of the following snippet?

a. (1, 2)

b. 12

c.21

d.(2,1)
30. The following snippet:

a. will output 2

b. will cause a runtime error

c. will output 16

d.will output 4

You might also like