-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW7-8-9.py
95 lines (65 loc) · 2.03 KB
/
HW7-8-9.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
#HW7
def repN_ForSeq(phrase):
myStr = ""
repeat = 0
for character in phrase: #for each *blank* in the thing, *blank*, run some command
repeat = repeat + 1
myStr = myStr + character*repeat
print(myStr)
def repN_ForInd(word):
end = ""
for number in range(len(word)):
variable = number + 1
end = end + word[number]*variable
print(end)
def repN_WhileInd(emily):
count = 0
strig = ""
while count < len(emily):
strig = strig + emily[(count)]*(count + 1)
count = count + 1
print(strig)
def repN_Recur(n):
if n == "" :
return n
else:
return repN_Recur(n[:-1]) + n[len(n)-1]*len(n)
hello = "emily"
print(repN_Recur(hello))
#HW8
def flip_char(input):
output = ""
#imma go through each letter of the input and if upper case then lower it else upper it
for character in input:
if character.isupper():
output = output + character.lower()
else:
output = output + character.upper()
return output
def format_name(input):
if input.count(" ") == 2:
return input[input.find(" ", input.find(" ") + 1) + 1:] + ", " + input[:input.find(" ")] + " " + input[input.find(" ") + 1:][0] + "."
elif input.count(" ") == 1:
return input[input.find(" ") + 1:] + ", " + input[:input.find(" ")]
hello = "Ethan Lee"
print(format_name(hello))
a_list = ['cs', 'math', ['bio', 'chem'], 'cogsci',
['history', 'econ', 'music']]
val3 = a_list[::2]
val3.insert(1,val3[2][1])
print(val3)
#HW9
tim = [['CSCI51P', 90], ['CSCI62', 92],['Math101', 87],['Econ51', 97]]
bob = [['CSCI51P', 78], ['Econ52', 94],['Econ151', 60],['Math101', 95], ['Math60', 82]]
def getCourses(n_list, grade):
my_list = []
for a_list in n_list:
if a_list[1] > grade:
my_list.append(a_list[0])
return my_list
def avgGrade(n_list):
total = 0
for a_list in n_list:
total += a_list[1]
return total/len(n_list)
print(avgGrade(tim))