forked from ColinOBrien90/quiz-itp-w1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
132 lines (99 loc) · 3.07 KB
/
main.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
"""Intro to Python - Week 1 - Quiz."""
# Question 1
def question_1():
"""Return the correct answer for the following question.
What's the correct data type of the following values: True, False
a) Integer
b) Boolean
c) String
d) Collection
"""
# Return the correct value.
return "Boolean"
# Question 2
def question_2():
"""Return the correct answer for the following question.
What's the final result of the following operation:
result = True or ("" and False and []) or (1 and "hello world")
a) []
b) 1
c) True
d) False
e) "hello world"
"""
# Return the correct value.
return True
# Question 3
def remove_Es(a_string):
"""Implement the code required to make this function work.
Write a function `remove_Es` that receives a string and removes all
the characters `'e'` or `'E'`. Example:
remove_Es('remoter') # 'rmotr'
remove_Es('eEe') # ''
remove_Es('abc') # 'abc'
"""
# Write your code here
def remove_Es(x):
for i in x:
if i == 'e' or 'E':
del(i)
return x
return x
# Question 4
def question_4():
"""Return the correct answer for the following question.
Given the following two collections:
a_tuple = (19, 33, 12)
a_list = range(0, 10)
What's the final value of `result`?
result = a_list[3**2 - 8] + a_list[-1] + a_tuple[2]
"""
# Return the correct value.
return result [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1], (19, 33, 12, 2)
# Question 5
def calculate_tax(income):
"""Implement the code required to make this function work.
Write a function `calculate_tax` that receives a number (`income`) and
calculates how much of Federal taxes is due,
according to the following table:
| Income | Tax Percentage |
| ------------- | ------------- |
| <= $50,000 | 15% |
| <= $75,000 | 25% |
| <= $100,000 | 30% |
| > $100,000 | 35% |
Example:
income = 30000 # $30,000 is less than $50,000
calculate_tax(income) # $30,000 * 0.15 = 4500 = $4,500
income = 80000 # $80,000 is more than $75,000 but less than $80,000
calculate_tax(income) # $80,000 * 0.25 = 20000 = $20,000
income = 210000 # $210,000 is more than $100,000
calculate_tax(income) # $210,000 * 0.35 = 73500 = $73,500
"""
# Write your code here
def calculate_tax(income):
if income <= 50000:
income *= 0.15
return '$' + str(int(income))
elif income => 50000 and <= 74999:
income *= 0.25
return '$' + str(int(income))
# Question 6
def matrix_sum(a_matrix):
"""Implement the code required to make this function work.
Write a function `matrix_sum` that sums all the values in a square matrix.
Example:
m1 = [
[2, 9, 1],
[3, 1, 18],
[22, 8, 16]
]
m2 = [
[81, 29],
[31, 57]
]
matrix_sum(m1) # 80
matrix_sum(m2) # 198
"""
# Write your code here
pass