-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathChapter 2_Python quiz.py
More file actions
138 lines (78 loc) · 2.16 KB
/
Chapter 2_Python quiz.py
File metadata and controls
138 lines (78 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
1.Question 1
In the following code,
print(98.6)
What is "98.6"?
<A> A variable
<B> A constant
<C> An iteration / loop statement
<D> A conditional statement
AnS: <B> A constant
2.Question 2
What does the following code print out?
print("123" + "abc")
<A> 123abc
<B> This is a syntax error because you cannot add strings
<C> hello world
<D> 123+abc
AnS: <A> 123abc
3.Question 3
Which of the following is a bad Python variable name?
<A> spam_23
<B> Spam
<C> spam23
<D> spam.23
AnS: <C> spam23
4.Question 4
Which of the following is not a Python reserved word?
<A> speed
<B> else
<C> for
<D> if
AnS: <A> speed
5.Question 5
Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do?
x = x + 2
<A> Retrieve the current value for x, add two to it and put the sum back into x
<B> Produce the value "false" because "x" can never equal "x+2"
<C> Create a function called "x" and put the value 2 in the function
<D> This would fail as it is a syntax error
AnS: <A> Retrieve the current value for x, add two to it and put the sum back into x
6.Question 6
Which of the following elements of a mathematical expression in Python is evaluated first?
<A> Parentheses ( )
<B> Subtraction -
<C> Addition +
<D> Multiplication *
AnS: <A> Parenthesis ( )
7.Question 7
What is the value of the following expression
42 % 10
Hint - the "%" is the remainder operator
<A> 10
<B> 4210
<C> 2
<D> 0.42
AnS: <C> 2
8.Question 8
What will be the value of x after the following statement executes:
x = 1 + 2 * 3 - 8 / 4
<A> 1.0
<B> 5.0
<C> 2
<D> 3
Ans: <B> 5.0
9.Question 9
What will be the value of x when the following statement is executed:
x = int(98.6
<A> 98
<B> 6
<C> 99
<D> 100
Ans: <A> 98
10.Question 10
What does the Python input() function do?
<A> Pause the program and read data from the user
<B> Connect to the network and retrieve a web page.
<C> Read the memory of the running program
<D> Take a screen shot from an area of the screen
AnS: <A> Pause the program and read data from the user