-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexttoaudio.py
135 lines (112 loc) · 3.33 KB
/
texttoaudio.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
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
# Week 2 Assignment
def primeproduct(m):
primelist = []
if m < 0:
return False
else:
for i in range(2, m + 1):
for p in range(2, i):
if (i % p) == 0:
break
else:
primelist.append(i)
for x in primelist:
y = m / x
if y in primelist:
return True
return False
def delchar(s, c):
if len(c) > 1:
return s
else:
return s.replace(c, '')
def shuffle(l1, l2):
list_length = min(len(l1), len(l2))
new_list = []
for i in range(list_length):
new_list.extend([l1[i], l2[i]])
if len(l1) > list_length:
new_list.extend(l1[list_length:])
if len(l2) > list_length:
new_list.extend(l2[list_length:])
return new_list
#Week 3 Assisgnment
def contracting(l):
result = 'True'
if len(l) > 2:
for v in range(len(l) - 2):
abs_diff = abs(l[v] - l[v + 1])
abs_diff_2 = abs(l[v + 1] - l[v + 2])
if abs_diff <= abs_diff_2:
result = 'False'
break
return result
def counthv(list):
result = [0, 0] #first is hc(hill_count) and second is vc(valley_count)
if len(list) > 2:
for v in range(1, len(list) - 1):
if max(list[v], list[v + 1], list[v - 1]) == list[v]:
result[0] = result[0] + 1
elif min(list[v], list[v + 1], list[v - 1]) == list[v]:
result[1] = result[1] + 1
return result
def leftrotate(m):
new_matrix = [[m[j][i] for j in range(len(m))]
for i in range(len(m[0]) - 1, -1, -1)]
return new_matrix
def frequency(l):
unique_l = list(set(l))
freq_list = [l.count(x) for x in unique_l]
min_freq_list = [
unique_l[x] for x in range(len(freq_list))
if freq_list[x] == min(freq_list)
]
max_freq_list = [
unique_l[x] for x in range(len(freq_list))
if freq_list[x] == max(freq_list)
]
min_freq_list.sort()
max_freq_list.sort()
return (min_freq_list, max_freq_list)
def onehop(list):
new = []
for i in range(len(list)):
for j in range(len(list)):
if i != j and list[i][1] == list[j][0]:
q = list[i][0]
w = list[j][1]
if q != w:
t = (q, w)
if t not in new:
new.append(tuple(t))
new.sort()
return (new)
courses = []
students = {}
grades = {}
while True:
s = input()
if s == "Courses":
d = 1
elif s == "Students":
d = 2
elif s == "Grades":
d = 3
elif s == "EndOfInput":
break
else:
s = s.split("~")
if d == 1:
courses.append(s)
elif d == 2:
students[s[0]] = s[1]
grades[s[0]] = []
elif d == 3:
grades[s[-2]].append(s[-1])
points = {"A": 10, "AB": 9, "B": 8, "BC": 7, "C": 6, "CD": 5, "D": 4}
for idx in sorted(grades):
p = [points[x] for x in grades[idx]]
n = len(p) or 1
marks = str(round(sum(p) / n, 2)) if p else "0"
d = [idx, students[idx], marks]
print("~".join(d))