-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject08.py
118 lines (96 loc) · 3.35 KB
/
project08.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
"""
Course: CS101
File: Project 08
Project: 08
Author: Alfredo Pena
Description:
It tells the user their tax rate according to income and status.
"""
"""
Instructions:
Complete the two functions below so they calculate the correct tax rates.
"""
import random
# TODO - Complete this function
def calculateSingleTax(monthlyIncome):
"""calculateSingleTax - given monthly income, it returns the tax rate"""
a = monthlyIncome * 12
if a == 0:
return 0
elif 1 <= a <= 9525:
return 10
elif 9526 <= a <= 38700:
return 12
elif 38701 <= a <= 82500:
return 22
elif 82501 <= a <= 157500:
return 24
elif 157501 <= a <= 200000:
return 32
elif 200001 <= a <= 500000:
return 35
else:
return 37
# TODO - Complete this function
def calculateMarriedTax(husbandIncome, wifeIncome):
"""calculateMarriedTax - given yearly incomes for both husband
and wife, return the married tax rate"""
pass
a = husbandIncome + wifeIncome
if a == 0:
return 0
elif 1 <= a <= 19050:
return 10
elif 19051 <= a <= 77400:
return 12
elif 77401 <= a <= 165000:
return 22
elif 165001 <= a <= 315000:
return 24
elif 315001 <= a <= 400000:
return 32
elif 400001 <= a <= 600000:
return 35
else:
return 37
# =======================================================================
# Main code - Do not change any code below this comment.
"""
Testing calculateSingleTax(). To pass all of these tests, you must
implement the tax rate table and have calculateSingleTax() return the
correct tax rate for these monthly income values.
If one of more of these asserts() fail (ie., stop your program), you
must fix the issue in the calculateSingleTax() function.
"""
assert(calculateSingleTax(0) == 0)
assert(calculateSingleTax(593) == 10)
assert(calculateSingleTax(793) == 10)
assert(calculateSingleTax(794) == 12)
assert(calculateSingleTax(2725) == 12)
assert(calculateSingleTax(6693) == 22)
assert(calculateSingleTax(9797) == 24)
assert(calculateSingleTax(15584) == 32)
assert(calculateSingleTax(37518) == 35)
assert(calculateSingleTax(41666) == 35)
assert(calculateSingleTax(42695) == 37)
print('You passed all of the tests for calculateSingleTax()')
"""
Testing calculateMarriedTax(). To pass all of these tests, you must
implement the tax rate table and have calculateMarriedTax() return the
correct tax rate for these yearly income values for a married couple.
If one of more of these asserts() fail (ie., stop your program), you
must fix the issue in the calculateMarriedTax() function.
"""
assert(calculateMarriedTax(0, 0) == 0)
assert(calculateMarriedTax(0, 1) == 10)
assert(calculateMarriedTax(1, 0) == 10)
assert(calculateMarriedTax(593, 345) == 10)
assert(calculateMarriedTax(6794, 13002) == 12)
assert(calculateMarriedTax(32725, 12345) == 12)
assert(calculateMarriedTax(36693, 42345) == 22)
assert(calculateMarriedTax(109797, 72345) == 24)
assert(calculateMarriedTax(315584, 42345) == 32)
assert(calculateMarriedTax(337518, 99245) == 35)
assert(calculateMarriedTax(341666, 62345) == 35)
assert(calculateMarriedTax(242695, 472345) == 37)
print('You passed all of the tests for calculateMarriedTax()')