You are on page 1of 31

Name: __________________________________________

1. Python is an example of:


A. a machine language
B. a high-level programming language
C. a natural language

2. What do you call a computer program which directly executes instruction written
in a programming language?
A. A compiler
B. A translator
C. An interpreter

3. What Python version is covered in this course?


A. Python 3
B. Python 2
C. Python 1

4. Which one of the following is an example of a Python file extension?


A. .p
B. .py
C. .pi

5. What is true about compilation? (Select Two answers)


A. It tend to be faster than interpretation
B. The code is converted directly into machine code executable by the processor
C. It tend to be slower than interpretation
D. Both you and the end user must have the compiler to run your code

6. What is the expected behavior of the following Program?


Print(“Hello!”)
A. The program will generate an error message on the screen
B. The program will output (“Hello!”) to the screen
C. The program will output Hello! to the screen
D. The program will output “Hello!” to the screen
7. Select the true statements? (Select two answers)
A. Python is free, open-source, and multiplatform
B. Python 3 is backward compatible with Python 2
C. Python is a good choice for low-level programming. E.g., when you want to
implement an effective driver
D. Python is a good choice for creating and executing tests for application

8. What is the expected behavior of the following program?

print(“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

9. What is the output of the following snippet?


y = 2 + 3 * 5.
print(y)

A. 17
B. The snippet will cause an execution error
C. 17.0
D. 25.

10. What is the Output of the following snippet if the user enters two lines containing
“11” and “4” respectively?
x = int(input())
y = int(input())

x=x%y
x=x%y
y=y%x
print(y)

A. 2
B. 3
C. 1
D. 4
11. The meaning of the keyword parameter is determined by:
A. The argument’s name specified along with its value.
B. Its connection with existing variables
C. Its position within the argument list
D. Its value

12. What is the output of the following snippet if the user enters two line containing “2”
and “4” respectively?
x = int(input())
y = int(input())

x=x/y
y=y/x
print(y)

A. The code will cause a runtime error.


B. 4.0
C. 8.0
D. 2.0

13. What it the output of the following snippet if the user enters two lines containing
“3” and “6” respectively?
x = input()
y = int(input())

print (x * y)

A. 666
B. 18
C. 333333
D. 36

14. The “\n” digraph force the “print()” function to:


A. Break the output line
B. Duplicate the character next to the digraph
C. Stop its execution
D. Output exactly two characters: \ and n
15. What is the output of the following snippet?
z=y=x=1
print(x, y, z, sep =”*”)

A. 111
B. 1*1*1
C. x*y*z
D. xyz

16. Left-sided binding determines that the result of the following expression:
1 // 2 * 3
Is equal to:

A. 4.5
B. 0.0
C. 0
D. 0.16666666666666666666

17. Which of the following statements are true? (Select two answers)
A. The ** operator uses right-sided blinding.
B. Addition precedes multiplication.
C. The right arguments of the % operator cannot be zero.
D. The result of the / operator is always an integer value.

18. What is the output of the following snippet if the user enters two lines containing 2
and 4 respectively?
x = input()
y = input()
print (x + y)

A. 4
B. 24
C. 6
D. 2
19. What is the output of the following snippet?
x=1
y=2
z=x
x=y
y=z
print(x, y)

A. 21
B. 22
C. 11
D. 12

20. Which of the following variable name are illegal? (Select two answers)
A. TRUE
B. true
C. True
D. and

21. The ** operator:


A. Does not exist
B. Performs duplicated multiplication
C. Performs exponentiation
D. Performs floating-point multiplication

22. What is the output of the following snippet if the user enters two line containing 2
and 4 respectively?
x = int(input())
y = int(input())

x=x//y
y=y//x

print(y)

A. The code will cause a runtime error


B. 2.0
C. 8.0
D. 4.0
23. The print() function can output values of:
A. Just one argument
B. Not more than five arguments
C. Any number of arguments (including zero)
D. Any number of arguments (excluding zero)

24. What is the output of the following snippet?


x = 1 / 2 + 3 // 3 + 4 **2
print(x)

A. 8
B. 17.5
C. 17
D. 8.5

25. The meaning of the positional parameter is determined by its:


A. Position
B. Name
C. Appearance

26. The most important difference between integer and floating-point number lies in
the fact that:
A. Integers cannot be literals, while floats can
B. They cannot be used simultaneously
C. They are stores differently in the computer memory

27. The // operator


A. Does not exist
B. Performs integer division
C. Performs regular division

28. The result of the following addition: 123 + 0.0


A. Is equal to 123.0
B. Cannot be evaluated
C. Is equal to 123
29. A keyword is a word that (select two answers)
A. Is the most important word in the whole program
B. Cannot be used as a variable name
C. Cannot be used as a function name

30. A value returned by the input() function is:


A. a string
B. an integer
C. a float

31. An operator able to check whether two values are not qual is coded as:
A. !=
B. not ==
C. <>

32. How many star will the following snippet send to the console?
i=2
while i >= 0:
print(“*”)
i-=2

A. Three
B. One
C. Two

33. How many hashes will the following snippet send to the console?
for i in range(-1, 1):
print(“#”)

A. Three
B. Two
C. One
34. What value will be assigned to the x variable?
z = 10
y=0
x = z > y or z == y

A. False
B. True
C. 1

35. What is the output of the following code?


my_list = [3, 1, -1]
my_list[-1] = my_list[-2]
print(my_list)

A. [3, 1, 1]
B. [3, -1, 1]
C. [1, 1, -1]

36. Take a look at the snippet and choose one of the following statements which is true:
nums = []
vals = nums
vals.append(1)

A. vals is longer than nums


B. nums is longer than vals
C. nums and vals are of the same length

37. Take a look at the snippet and choose one of the following statement which is true:
nums = [ ]
vals = nums[ : ]
vals.append(1)

A. vals is longer than nums


B. nums and vals are of the same length
C. nums is longer than vals
38. How many elements does the my_list list contain?
my_list = [0 for I in range (1, 3)]

A. Three
B. Two
C. One

39. What is the output of the following snippet?


my_list = [0, 1, 2, 3]
x=1
for elem in my_list:
x *= elem
print(x)

A. 0
B. 6
C. 1

40. What is the output of the following snippet?


list1 = [3, 1, -2]
print(list1[list1[-1]])

A. 3
B. 1
C. -2

41. A function definition start with the keyword:


A. function
B. def
C. fun

42. A function parameter is a kind of variable accessible:


A. Only after the function definition’s completion
B. Only inside the function
C. Anywhere in the code.
43. A way of argument passing in which the order of the arguments determines the
initial parameters’ value is referred to as:
A. Positional
B. Sequential
C. Ordered

44. Which of the following statements are true? (select two answers)
A. The return keyword forces the function’s execution to terminate
B. The return keyword forces the function to restart its execution
C. The return keyword may cause the function to return a value

45. The none keyword designates:


A. An empty instruction
B. A function which doesn’t return a value
C. A none value

46. A variable defined outside a function:


A. May be read, but not written (something more is needed to do so)
B. May not be accessed in any way inside the function
C. May be freely accessed inside the function

47. If a list is passed into a function as an argument, deleting any of its elements inside
the function using the “ del “ instruction:
A. Will affect the argument
B. Will not affect the argument
C. Will cause a runtime error

48. What is the output of the following snippet?


def fun(in=2, out=3):
return in * out

print (fun (3))

A. 9
B. 6
C. The snippet is erroneous (invalid syntax)
49. What is the output of the following snippet?
tup = (1, ) + (1, )
tup = tup + tup
print(len(tup))

A. 2
B. 4
C. The snippet is erroneous (invalid syntax)

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

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


B. def fun(a=b=0):
C. def fun(a=0, b=0):
D. fun fun(a, b=0):

51. What is the output of the following snippet?


var = 1
def any():
print(var + 1, end=’ ‘)

any()
print(var)

A. 22
B. 11
C. 21
D. 12
52. What is the output of the following snippet?
my_list = ['Mary', 'had', 'a', 'little', 'lamb']

def my_list(my_list):
del my_list[3]
my_list[3] = "ram"

print(my_list(my_list))

A. [‘Mary’, ‘had’, ‘a’, ‘ram’]


B. [‘Mary’, ‘had’, ‘a’, ‘little’, ‘lamb’]
C. [‘Mary’, ‘had’, ‘a’, ‘lamb’]
D. No output, the snippet is erroneous

53. What is the output of the following snippet?


def fun (inp=2, out=3):
return inp * out

print(fun(out=2))

A. 4
B. The snippet is erroneous
C. 2
D. 6

54. What is the output of the following snippet?


def fun(x):
if x % 2 == 0:
return 1
else:
return

print(fun(fun(2)) + 1)

A. 1
B. The code will cause a runtime error
C. None
D. 2
55. A built-in function is a function which:
A. Has been placed within your code by another programmer
B. Has to be imported before use
C. Is hidden from programmers
D. Comes with Python, and is an integral part of Python

56. The following snippet:


def func(a,b):
return a**a

print(func(2))

A. will output – 4
B. is erroneous
C. will output – 2
D. will return – None

57. What is the output of the following snippet?


dic = {'one': 'two', 'three': 'one', 'two': 'three'}
v = dic['one']

for k in range(len(dic)):
v = dic[v]

print(v)

A. three
B. two
C. (‘one’, ‘two’, ‘three’)
D. one
58. The following snippet:
def f1(a):
return a ** a

def f2(a):
return f2(a) * f2(a)

print(f2(2))

A. is erroneous
B. will output = 2
C. will output = 16
D. will output = 4

59. What is the output of the following snippet?


def fun(x, y, z):
return x + 2 * y + 3 * z

print(fun(0, z=1, y=3))

A. 3
B. 0
C. The snippet is erroneous
D. 9

60. What is the output of the following snippet?


def fun(x):
x +=1
return x

x=2
x = fun(x + 1)
print(x)

A. 4
B. The code is erroneous
C. 5
D. 3
61. What is the output of the following snippet?
def fun(x):
global y
y=x*x
return y

fun(2)
print(y)

A. None
B. The code will cause a runtime error
C. 4
D. 2

62. What code would you insert instead of the comment to obtain the expected output?
Expected Output:
a
b
c

code:
dictionary = {}
my_list = [‘a’, ‘b’, ‘c’, ‘d’]

for i in range(len(my_list) – 1):


dictionary[my_list[i]]= (my_list[i], )

for i in sorted(dictionary.keys()):
k = dictionary[i]
# Insert your code here.

A. print(k)
B. print(k[0])
C. print(k[‘0’])
D. print(k[“0”])
63. What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup = tup[1:-1]
tup = tup[0]
print(tup)

A. (2)
B. 2
C. (2, )
D. The snippet is erroneous

64. What is the output of the following snippet?


def f(x):
if x == 0:
return 0
return x + f(x -1)

print(f(3))

A. 3
B. 1
C. The code is erroneous
D. 6

65. Which one of the following lines properly starts a parameter less function
definition?
A. function fun():
B. fun function():
C. def fun():
D. def fun:

66. The fact tuple belong to sequence types 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
67. What is the output of the following snippet?
dd = {“1” : “0”, “0”:”1”}
for x in dd.vals():
print(x, end=” ”)

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


B. 10
C. 01
D. 00

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


a=1
b=0
a=a^b
b=a^b
a=a^b
print(a,b)

A. 11
B. 01
C. 10
D. 00

69. How many elements does the “ List_1” list contain?


List_1 = [i for i in range(-1, -2)]

A. zero
B. one
C. two
D. three
70. The following snippet:
def function_1(a):
return None

def function_2(a):
return function_1(a) * function_1(a)

print(function_2(2))

A. Will cause a runtime error


B. Will output 2
C. Will output 4
D. Will output 16

71. What is the output of the following snippet?


tup = (1, 2, 4, 8)
tup = tup[-2:-1]
tup = tup[-1]
print(tup)

A. 44
B. (4)
C. 4
D. (4, )

72. Assuming that “ my_tuple” is a correctly created tuple, the fact that tuples are
immutable means that the following instruction:
my_tuple[1] = my_tuple[1] + my_tuple[0]

A. May be illegal of the tuple contains strings


B. Can be executed if and only if the tuple contains at least two elements
C. Is illegal
D. Is fully correct
73. What is the output of the following snippet?
dct = {‘one’:’two’, ‘three’:’one’, ‘two’:’three’}
v = dct[‘three’]

for k in range(len(dct)):
v = dct[v]

print(v)

A. three
B. (‘one’, ‘two’, ‘three’)
C. two
D. one

74. What values will be assigned to the “ x ” variable?


z=0
y = 10
x = y < z and z > y or y > z and z < y
print(x)

A. True
B. False
C. 1
D. 0

75. What is the output of the following piece of code if the user enters two lines
containing “ 2 “ and “ 4 “ respectively?
x = float (input())
y = float (input())
print(y ** (1/x))

A. 0.0
B. 2.0
C. 1.0
D. 4.0
76. What is the output of the following snippet?
def fun(x):
if x % 2 == 0:
return 1
else:
return 2

print(fun(fun(2)))

A. 2
B. The code will cause a runtime error
C. 2None
D. 1

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


print(“a”, “b”, “c”, sep=”sep”)

A. abc
B. asepbsepc
C. asepbsepcsep
D. abc

78. The result of the following division: 1 // 2


A. is equal to 0.5
B. is equal to 0.0
C. is qual to 0
D. cannot be predicted

79. What is the output of the following snippet?


def fun(inp=2, out=3):
return inp * out

print(fun(out=2))

A. 2
B. 6
C. The snipper is erroneous and will cause SyntaxError
D. 4
80. What is the output of the following piece of code?
x=1
y=2
x, y, z = x, x, y
z, y, z = x, y, z

print(x, y, z)

A. 212
B. 122
C. 112
D. 121

81. How many stars(*) will the following snippet send to the console?
i=0
while i < i + 2:
i+=1
print(“*”)
else:
print(“*”)

A. One
B. Zero
C. The snippet will enter an infinite loop. Printing one star per line
D. Two

82. Take a look at the snippet and choose the true statements:
nums = [1, 2, 3]
vals = nums
del vals[:]

A. vals is longer than nums


B. the snippet will cause a runtime error
C. nums is longer than vals
D. nums and vals have the same length
83. What is the output of the following snippet?
def fun(x, y):
if x ==y:
return x
else:
return fun(x, y-1)

print(fun(0, 3))

A. The snippet will cause a runtime error


B. 1
C. 0
D. 2

84. Which of the following variable names are illegal and will cause Syntax Error
exception? (Select two answers)
A. print
B. In
C. for
D. in

85. What is the output of the following piece of code if the user enters two lines
containing “ 3 “ and “ 6 “ respectively?
y = input()
x = input()
print(x + y)

A. 3
B. 63
C. 6
D. 36
86. What is the output of the following snippet?
my_list = [1, 2]
for v in range (2):
my_list.insert(-1, my_list[v])

print(my_list)

A. [2, 1, 1, 2]
B. [1, 1, 1, 2]
C. [1, 2, 2, 2]
D. [1, 2, 1, 2]

87. What is the output of the following piece of code if the user enters two lines
containing “ 3 “ and “ 2 “ respectively?
x = int(input())
y = int(input())

x=x%y
x=x%y
y= y % x
print(y)

A. 3
B. 2
C. 0
D. 1

88. The meaning of a positional arguments is determined by:


A. The argument’s name specified along with its value
B. Its connection with existing variables
C. Its position within the arguments list
D. Its value
89. What is the output of the following snippet?
my_list = [x * x for x in range(5)]

def fun(lst):
del lst[lst[2]]
return lst

print(fun(my_list))

A. [0, 1, 4, 9]
B. [1, 4, 9, 16]
C. [0, 1, 9,16]
D. [0, 1, 4,16]

90. What is the output of the following snippet?


dct ={}
dct[‘1’] = (1,2)
dct[‘2’]=(2,1)

for x in dct.keys():
print(dct[x][1], end=””)

A. 12
B. 21
C. (1,2)
D. (2,1)
91. How many hashes (#) will the following snippet send to the console?
lst = [[x for x in range(3)] for y in range(3)]

for r in range (3):


for c in range(3):
if lst[r][c] %2 != 0:
print(“#”)

A. six
B. nine
C. zero
D. three

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


x = 1//5 + 1/5

A. 0.4
B. 0
C. 0.2
D. 0.0

93. Which number is item East, In the displayed list?

A. 1
B. 3
C. 2
D. 4
94. Which punctuation symbol should be used to combine string and number in a print
statement?
A. ,
B. &
C. +
D. @

95. Which is true of variables? Choose three answers.


A. Variables must include at least on number
B. Variables are case-sensitive
C. Variables must include punctuation marks to signify new words
D. Variables cannot begin with a number
E. Variables cannot have spaces in their names

96. Which built-in function should be wrapped around the variable, widget, to cast it
into a string variable?

A. str
B. string
C. stringtype
D. cast/str

97. Which comparison operator asks whether a value is qual to another?


A. =
B. >=
C. <=
D. ==
98. What is the correct order for order of operations?
A. Parentheses, Exponents, Multiplication, Division, Addition, Subtraction
B. Addition, Subtraction, Exponents, Parentheses, Multiplication, Division
C. Exponents, Parentheses, Addition, Subtraction, Multiplication, Division
D. Parentheses, Exponents, Addition, Subtraction, Multiplication, Division

99. Which is the symbol that concatenates variables in Python programming?


A. &
B. +
C. @
D. *

100. Lists are variables which store multiple values.


A. True
B. False

101. Which number will be shown when the sales variable is run in a print statement?

A. 31000
B. 53235
C. 30000
D. 32000
102. Which type of variables uses decimals?
A. Integer
B. Boolean
C. Floating
D. String

103. Which type of variable is displayed?

A. Integer
B. String
C. Boolean
D. Floating

104. Based on the assignments displayed on line 2, the print statement on line six is False:

A. True
B. False

105. Which symbol represents multiplication in arithmetic operators?


A. *
B. +
C. /
D. X
106. Which region and sales will come up based upon the print statement displayed on
line 6?

A. North Sales; 30000


B. East Sales; 40000
C. West Sales; 35000
D. South Sales; 20000

107. Which first name variable is an example of camel casing?


A. firstname
B. firstName
C. first Name
D. first.name

108. Which entry should be in the blue highlighted area in order to implements properly
the pass keyword?

A. pass
B. pass statement
C. begin pass
D. pass keyword
109. Which entry should be in the blue highlight area in order to set up correctly a break
statement?

A. break End
B. break loop
C. break while loop
D. break

110. Which entry should be in the blue highlighted area in order to set up correctly the
for loop to cover every month of the year?

A. 1,13
B. 1,12
C. 0,12
D. 12
111. Select the correct from of the if statement from multiple answer in the code sample
in order to return the print statements shown for customers who have annual sales
of at least 500,000.

A. if>=500000:
B. if annualSales >= 500000:
C. if annualSales = 500000:
D. if = 500000:

You might also like