-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_assessment.py
More file actions
77 lines (54 loc) · 1.5 KB
/
python_assessment.py
File metadata and controls
77 lines (54 loc) · 1.5 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
# Task: Complete the missing conditions to categorize age.
def categorize_age(age):
# Fill the missing conditions
if :
return "Child"
elif :
return "Teenager"
elif :
return "Adult"
else:
return "Senior"
# Task: Complete the function so it returns the sum of all positive numbers in a list.
def sum_positive(nums):
total = 0
# Fill in the loop and condition
for :
if :
return total
def count_words(words):
counts = {} # dictionary to store word → frequency
# TODO: If the word is not in counts, initialize it.
# TODO: Otherwise, increase its count.
return counts
# Test the function count_words
sample = ["apple", "banana", "apple", "orange", "banana", "apple"]
print(count_words(sample))
# Expected output (order may vary):
# {'apple': 3, 'banana': 2, 'orange': 1}
# Task: Fix the missing parts to avoid errors.
def divide(a, b):
try:
result = # perform division
return result
except : # fill error type
return "Cannot divide by zero"
class Rectangle:
def __init__(self):
self. = width
self. = height
def area(self):
# return area
return
def perimeter(self):
# return perimeter
return
class :
def __init__(self, name):
self.name = name
def speak(self):
return # base behavior
class Dog():
def speak(self):
# override behavior
return