-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrying_stuff.py
More file actions
120 lines (78 loc) · 2.47 KB
/
Copy pathtrying_stuff.py
File metadata and controls
120 lines (78 loc) · 2.47 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
def createStudent(name, age, grades=[]):
return {
"name": name,
"age": age,
"grades": grades
}
chrisley = createStudent("Chrislea", 15)
dallas = createStudent('Dallas', 16)
def addGrade(student, grade):
student['grades'].append(grade)
# To help visualize the grades we have added a print statement
print(student['grades'])
addGrade(chrisley, 90)
addGrade(dallas, 100)
print(id(chrisley['grades']))
print(id(dallas['grades']))
print("---------------------------------")
age = 27
def func():
age = 70
def inner_func():
global age
print(age)
inner_func()
func()
print("----------")
def first_function(height):
def second_function(var1, var2):
return var1 * height * var2
return second_function
result = first_function(20)
print(result(1, 2))
print("----------")
prices = [1, 2, 3, 4, 3, 2, 1, 3, 3]
def add_tax(price):
return price + price * .2
def add_bill(price):
return price * 2
def return_result(funcione, list_arg: list):
new_list = []
for i in list_arg:
total = funcione(i)
new_list.append("Ia aci:{nr}".format(nr=total))
return new_list
print(return_result(add_bill, prices))
print("-----------Map built-in higher-order function-------------")
int_list = [2, 3, 1, 3, 10]
doubled = map(lambda inp: inp * 2, int_list)
print(list(doubled))
list_items_to_double = [2, 2, 2, 2, 2]
def double_function(thing):
return thing * 2
result_double = map(double_function, list_items_to_double)
print(result_double)
print("-----------Coding question-------------")
# Say we stored our course grades in a list,
# but some of the grades were on a four-point scale and
# others were on a 100-point scale. To get all
# the grades on the same scale, try using a lambda
# function with the map() function to multiply just
# the grades on the four-point scale by 25 to get all
# of the grades on the same 100-point-scale.
grade_dict = {
"one": 3.5,
"two": 3.7,
"three": 2.6,
"four": 95,
"five": 87}
# Your code below:
# assign the result of your map function to the variable grades_100scale
grades_100scale = dict(
map(lambda raspuns: (raspuns[0] + "dadada", add_tax(raspuns[1])) if type(raspuns[1]) is float else raspuns,
grade_dict.items()))
# convert grades_100scale to a list and save it as updated_grade_list
updated_grade_dict = grades_100scale
# print updated_grade_list
print(grades_100scale)
print("----------------oop-------------")