-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCEP-30-02 1.2 Python's logic and s.txt
164 lines (138 loc) · 4.58 KB
/
PCEP-30-02 1.2 Python's logic and s.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
PCEP-30-02 1.2 Python's logic and structure:
1. Which of the following is not a Python keyword?
A: while
B: for
C: loop
D: if
2. What is the purpose of indentation in Python?
A: To make the code look neat
B: To define code blocks
C: To increase code execution speed
D: To declare variables
3. How do you write a single-line comment in Python?
A: // Comment
B: /* Comment */
C: # Comment
D: <!-- Comment -->
4. Which of the following is a valid Python instruction?
A: print "Hello, World!"
B: print("Hello, World!")
C: echo "Hello, World!"
D: console.log("Hello, World!")
5. What happens if you mix tabs and spaces for indentation in Python?
A: Nothing, it works fine
B: It raises an IndentationError
C: The code runs slower
D: It automatically converts all to spaces
6. Which keyword is used to define a function in Python?
A: function
B: def
C: define
D: func
7. What is the correct way to start an if statement in Python?
A: if (condition):
B: if condition
C: if: condition
D: if condition:
8. How do you write a multi-line comment in Python?
A: // Comment //
B: /* Comment */
C: ''' Comment '''
D: <!-- Comment -->
9. Which of the following is not a valid way to end a Python instruction?
A: Newline
B: Semicolon
C: Colon
D: Both A and B are valid
10. What does the `pass` keyword do in Python?
A: It skips the rest of the loop
B: It acts as a placeholder for future code
C: It raises an exception
D: It terminates the program
11. Which of the following is true about Python's `else` clause?
A: It can only be used with if statements
B: It can be used with for loops
C: It can be used with while loops
D: Both B and C are correct
12. What is the purpose of the `continue` keyword in Python?
A: To exit a loop
B: To skip the rest of the current iteration
C: To pause the program execution
D: To start a new function
13. How many spaces are recommended for each level of indentation in Python?
A: 2
B: 3
C: 4
D: 8
14. Which keyword is used to define a class in Python?
A: class
B: define
C: struct
D: object
15. What is the output of the following code?
```python
x = 5
if x > 0:
print("Positive")
else:
print("Non-positive")
print("Done")
```
A: Positive
B: Positive
Done
C: Non-positive
Done
D: Done
16. Which of the following is not a valid loop in Python?
A: for loop
B: while loop
C: do-while loop
D: All of the above are valid
17. What is the purpose of the `break` keyword in Python?
A: To exit a loop prematurely
B: To skip the current iteration
C: To define a function
D: To raise an exception
18. Which of the following is a valid way to import a module in Python?
A: #include <module>
B: import module
C: using module
D: require module
19. What is the correct way to start a while loop in Python?
A: while (condition):
B: while condition:
C: while: condition
D: while condition
20. Which keyword is used to handle exceptions in Python?
A: catch
B: except
C: handle
D: try
21. What is the purpose of the `finally` clause in exception handling?
A: To define the main code block
B: To specify what to do if no exception occurs
C: To execute code regardless of whether an exception occurred
D: To raise a custom exception
22. How do you define a lambda function in Python?
A: lambda: expression
B: def lambda(x): expression
C: lambda x: expression
D: function lambda(x) { expression }
23. What does the `global` keyword do in Python?
A: Declares a global variable
B: Imports a global module
C: Creates a global function
D: Defines a global constant
24. Which of the following is true about Python's `elif` keyword?
A: It's equivalent to "else if" in other languages
B: It can only be used once in an if-else chain
C: It must always be followed by an else clause
D: It can only be used with while loops
25. What is the purpose of the `with` statement in Python?
A: To define a new class
B: To handle exceptions
C: To ensure proper acquisition and release of resources
D: To create a new module
Answers:
1. C, 2. B, 3. C, 4. B, 5. B, 6. B, 7. D, 8. C, 9. C, 10. B, 11. D, 12. B, 13. C, 14. A, 15. B, 16. C, 17. A, 18. B, 19. B, 20. B, 21. C, 22. C, 23. A, 24. A, 25. C