-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_exercises.py
More file actions
159 lines (73 loc) · 1.89 KB
/
Copy pathimport_exercises.py
File metadata and controls
159 lines (73 loc) · 1.89 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
#!/usr/bin/env python
# coding: utf-8
# In[11]:
import functions_exercises as fe
fe.is_vowel('a')
# In[13]:
from functions_exercises import calculate_tip
calculate_tip(.20, 120)
# In[16]:
from functions_exercises import get_letter_grade as lg
lg(97)
# In[5]:
from itertools import product
list(product('ABC', [1,2,3]))
# In[8]:
from itertools import combinations
list(combinations('abcd', 2))
# In[9]:
from itertools import permutations
list(permutations('abcd', 2))
# In[2]:
import json
profiles = json.load(open('profiles.json'))
print(len(profiles))
# In[5]:
active = [n for n in profiles if n['isActive']]
len(active)
# In[7]:
not_active = [n for n in profiles if not n['isActive']]
len(not_active)
# In[8]:
total = 0
for n in profiles:
total += float(n['balance'].replace('$', '').replace(',', ''))
print(total)
# In[11]:
avg_bal = 0
for n in profiles:
avg_bal += float(n['balance'].replace('$', '').replace(',', ''))
print(round(avg_bal/len(profiles), 2))
# In[12]:
lowest = 5000
lowest_name = ''
for n in profiles:
bal = float(n['balance'].replace('$', '').replace(',', ''))
if bal < lowest:
lowest_name = n['name']
lowest = bal
print(lowest_name, lowest)
# In[13]:
highest = 1000
highest_name = ''
for n in profiles:
bal = float(n['balance'].replace('$', '').replace(',', ''))
if bal > highest:
highest_name = n['name']
highest = bal
print(highest_name, highest)
# In[14]:
fruits = [n['favoriteFruit'] for n in profiles]
sb_count = fruits.count('strawberry')
ap_count = fruits.count('apple')
ba_count = fruits.count('banana')
print('strawberry:', sb_count, 'apple:', ap_count, 'banana:', ba_count)
# In[17]:
total = 0
for n in profiles:
msg = n['greeting'].split(' ')
for i in msg:
if i.isdigit():
total += (int(i))
print(total)
# In[ ]: