-
Notifications
You must be signed in to change notification settings - Fork 242
/
wk2 - quiz.py
107 lines (76 loc) · 1.69 KB
/
wk2 - quiz.py
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
Question 1
Which of the following is a comment in Python?
* This is a test
// This is a test
# This is a test
/* This is a test */
Answer: # This is a test
Question 2
What does the following code print out?
print("123" + "abc")
This is a syntax error because you cannot add strings
hello world
123abc
123+abc
Answer: 123abc
Question 3
Which of the following is a bad Python variable name?
spam23
SPAM23
23spam
spam_23
Answer: 23spam
Question 4
Which of the following is not a Python reserved word?
spam
else
for
if
Answer: spam
Question 5
What does the following statement do?
x = x + 2
Exit the program
This would fail as it is a syntax error
Increase the speed of the program by a factor of 2
Retrieve the current value for x, add two to it and put the sum back into x
Answer: Retrieve the current value for x, add two to it and put the sum back into x
Question 6
Which of the following elements of a mathematical expression in Python is evaluated first?
Parenthesis ( )
Subtraction -
Multiplication *
Addition +
Answer: Parenthesis ( )
Question 7
What is the value of the following expression
42 % 10
Hint - the "%" is the remainder operator
0.42
420
1042
2
Answer: 2
Question 8
What is the value in x after the following statement executes:
x = 1 + 2 * 3 - 8 / 4
5
4
15
8
Answer: 5
Question 9
What value be in the variable x when the following statement is executed
x = int(98.6)
100
99
98
6
Answer: 98
Question 10
What does the Python raw_input() function do?
Connect to the network and retrieve a web page.
Take a screen shot from an area of the screen
Pause the program and read data from the user
Read the memory of the running program
Answer: Pause the program and read data from the user