forked from micanipho/Practice-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_code.py
More file actions
378 lines (278 loc) · 8.37 KB
/
student_code.py
File metadata and controls
378 lines (278 loc) · 8.37 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
"""Learning Outcome: Functions"""
def sum_of_squares(n: int):
"""
Calculate the sum of the squares of all integers from 1 to n.
Parameters:
n (int): A non-negative integer up to which the squares will be summed.
Returns:
int: The sum of the squares of all integers from 1 to n.
Raises:
ValueError: If n is a negative integer.
"""
n >= 0
return sum(n ** 2)
pass
def evaluate_performance(grades: list, min_pass: int):
"""
Evaluate the performance based on a list of grades and a minimum passing grade.
Parameters:
grades (list): A list of integers representing student grades.
min_pass (int): The minimum average grade required to pass.
Returns:
str: "Pass" if the average grade is greater than or equal to min_pass, otherwise "Fail".
"""
grades = []
for grade in grades:
if grade >= min_pass:
return "Pass"
if grade < min_pass:
return "Fail"
pass
def calculate_cumulative_performance(scores: dict):
"""
Calculate the cumulative performance based on student scores.
Parameters:
scores (dict): A dictionary where keys are subject names and values are the corresponding scores.
Returns:
dict: A dictionary containing the average score and a list of subjects where the score is below average.
"""
scores = {}
return scores
pass
def analyze_improvement(scores: list):
"""
Analyze the improvement trend based on a list of scores.
Parameters:
scores (list): A list of integers representing scores over time.
Returns:
dict: A dictionary containing the trend of improvement ("positive", "negative", or "neutral")
and a boolean indicating whether there has been an improvement.
"""
pass
def rank_students(students: list[tuple[str, int]]):
"""
Rank students based on their scores.
Parameters:
students (list): A list of tuples where each tuple contains a student's name and their score.
Returns:
list: A sorted list of tuples in descending order based on scores.
"""
pass
"""Learning Outcome: Basic Loops"""
def even_numbers(n: int):
"""
Generate a list of even numbers from 1 to n.
Parameters:
n (int): The upper limit for generating even numbers.
Returns:
list: A list of even integers from 1 to n.
"""
numbers = []
for num in range(1, 25):
if num % 2 == 0:
numbers.append(num)
return numbers
pass
def odd_numbers(n: int):
"""
Generate a list of odd numbers from 1 to n.
Parameters:
n (int): The upper limit for generating odd numbers.
Returns:
list: A list of odd integers from 1 to n.
"""
numbers = []
for num in range(1, 25):
if num % 2 != 0:
numbers.append(num)
return numbers
pass
def sum_multiples_of_num(num: int, length: int):
"""
Calculate the sum of multiples of a given number up to a specified length.
Parameters:
num (int): The number whose multiples are to be summed.
length (int): The upper limit for the range of multiples.
Returns:
int: The sum of multiples of num from 1 to length.
"""
pass
def skip_num(n: int, length: int):
"""
Generate a list of numbers from 1 to length, skipping a specific number.
Parameters:
n (int): The number to skip.
length (int): The upper limit for generating numbers.
Returns:
list: A list of integers from 1 to length, excluding n.
"""
pass
def break_test(n: int, length: int):
"""
Generate a list of numbers from 1 to length, stopping when a specific number is encountered.
Parameters:
n (int): The number at which to stop adding to the list.
length (int): The upper limit for generating numbers.
Returns:
list: A list of integers from 1 to length, excluding n and stopping before it.
"""
pass
def sum_numbers_until_zero(nums: list):
"""
Calculate the sum of numbers in a list until a zero is encountered.
Parameters:
nums (list): A list of integers.
Returns:
int: The sum of integers in the list up to (but not including) the first zero.
"""
nums = []
for num in nums:
if num != 0:
nums.append(sum(nums))
return nums
pass
def count_positive_numbers(nums: list):
"""
Count the number of positive integers in a list.
Parameters:
nums (list): A list of integers.
Returns:
int: The count of positive integers in the list.
"""
pass
def sum_dictionary_values(dictionary: dict):
"""
Calculate the sum of all values in a dictionary.
Parameters:
dictionary (dict): A dictionary with numeric values.
Returns:
int: The sum of all values in the dictionary.
"""
pass
def sum_unique_elements(elements: list):
"""
Calculate the sum of unique elements in a list.
Parameters:
elements (list): A list of integers.
Returns:
int: The sum of unique integers in the list.
"""
pass
def skip_divisible_by_num(n: int, length: int):
"""
Generate a list of numbers from 1 to length, skipping those that are divisible by a specific number.
Parameters:
n (int): The number to skip multiples of.
length (int): The upper limit for generating numbers.
Returns:
list: A list of integers from 1 to length, excluding those divisible by n.
"""
numbers = []
for num in range(1, 25):
if num % 3 != 0:
numbers.append(num)
return numbers
pass
"""Learning Outcome: Processing Data"""
def square_numbers(nums: list):
"""
Calculate the square of each number in a list.
Parameters:
nums (list): A list of integers.
Returns:
list: A list containing the squares of the input integers.
"""
pass
def transform_string(input: str, transform: str):
"""
Transform a string based on the specified transformation type.
Parameters:
input (str): The string to be transformed.
transform (str): The type of transformation ('capitalize', 'upper', 'lower').
Returns:
str: The transformed string.
Raises:
ValueError: If the transformation type is unknown.
"""
pass
def sum_and_average(nums: list[int]):
"""
Calculate the sum and average of a list of numbers.
Parameters:
nums (list[int]): A list of integers.
Returns:
tuple: A tuple containing the sum and average of the numbers.
"""
pass
def word_frequency_count(words: list[str]):
"""
Count the frequency of each word in a list.
Parameters:
words (list[str]): A list of words.
Returns:
dict: A dictionary with words as keys and their frequencies as values.
"""
pass
def filter_even_numbers(nums: list[int]):
"""
Filter out even numbers from a list.
Parameters:
nums (list[int]): A list of integers.
Returns:
list: A list containing only the even integers from the input list.
"""
pass
"""Learning Outcome: Simple Algorithms(Problem Solving)"""
def find_median(nums: list[int]):
"""
Find the median of a list of numbers.
Parameters:
nums (list[int]): A list of integers.
Returns:
float: The median value of the list.
Raises:
ValueError: If the list is empty.
"""
pass
def reverse_string(input: str):
"""
Reverse the given string.
Parameters:
input (str): The string to be reversed.
Returns:
str: The reversed string.
"""
return input[::-1]
pass
def largest_number(nums: list[int]):
"""
Find the largest number in a list.
Parameters:
nums (list[int]): A list of integers.
Returns:
int or None: The largest number in the list, or None if the list is empty.
"""
nums = []
for num in nums:
return max(num)
pass
def is_prime(n: int):
"""
Check if a number is prime.
Parameters:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
pass
def count_character_occurrences(word_sentence: str, char_count: str):
"""
Count the occurrences of a character in a given sentence.
Parameters:
word_sentence (str): The sentence in which to count occurrences.
char_count (str): The character to count.
Returns:
int: The number of occurrences of the character in the sentence.
"""
pass
print(skip_divisible_by_num(25, 6))