-
Notifications
You must be signed in to change notification settings - Fork 48
/
lab4.py
100 lines (78 loc) · 2.17 KB
/
lab4.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
from enum import Enum, auto
from lib230 import record
import math
class WaterType(Enum):
FRESH = auto()
BRACKISH = auto()
SALT = auto()
@record
class Fish:
name: str
weight_kg: float = 0
age_days: int = 0
species: str = 'unknown'
water_type: WaterType = WaterType.FRESH
def get_sum(lst):
"""Sums up the floats in a list
>>> get_sum([1.1, 2.2, 3.3, 4.4])
11.0
>>> get_sum([4.567])
4.567
>>> get_sum([])
0
"""
pass # replace with your code
def only_non_negative_sum(lst):
"""Sums up only the non-negative floats in a list
>>> only_non_negative_sum([1.1, -2.2, 3.3, -4.4])
4.4
>>> only_non_negative_sum([0.0])
0.0
>>> only_non_negative_sum([-1.7, -2.45, -3.1, -4.7])
0.0
"""
pass # replace with your code
def copy_even(lst):
"""Makes a copy of the given list, but only with those even numbers
>>> copy_even([1, 2,3, 4, 5, 6, 7, 8])
[2, 4, 6, 8]
>>> copy_even([-10, 0])
[-10, 0]
"""
pass # replace with your code
def copy_start_with_a(lst):
"""Makes a copy of the given list, but only with strings that start with a/A
>>> copy_start_with_a(['Apricot', 'Banana', 'Allison', 'a cookie'])
['Apricot', 'Allison', 'a cookie']
>>> copy_start_with_a(['', ' ', 'Amy'])
['Amy']
"""
pass # replace with your code
def copy_reverse(lst):
"""Makes a reverse copy of the given list, returns the copy
>>> copy_reverse([1.1, 2.2, 3.3, 4.4])
[4.4, 3.3, 2.2, 1.1]
>>> copy_reverse([4.567])
[4.567]
>>> copy_reverse([])
[]
"""
pass # replace with your code
def reverse(lst):
"""Reverses the given list in place
"""
pass # replace with your code
def cartesian_product(lst1, lst2):
"""Returns a list of cartesian products of the given lists
>>> cartesian_product([1.1, 2.2], [3.3, 4.6])
[3.63, 10.12]
"""
pass # replace with your code
def sort_number(lst):
"""Sorts the given list in ascending order in place
"""
pass # replace with your code
def sort_fish(lst):
"""Sorts Fish in the given list by weight in descending order in place
"""
pass # replace with your code