-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_my_tuition
More file actions
83 lines (80 loc) · 3.45 KB
/
calculate_my_tuition
File metadata and controls
83 lines (80 loc) · 3.45 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
"""Calculate UMD tuition based on the number of credits, residency, and differential tuition.
Full-time student if taking 12 or more credits.
Maryland residents pay a lower tuition.
Differential tuition applies to juniors and seniors in business, engineering, and computer science majors.
Examples of using the program:
python3 calculate_my_tuition.py -c 12 -nr -dt
python3 calculate_my_tuition.py --credits 15 --dt
python3 calculate_my_tuition.py --nonresident
"""
from argparse import ArgumentParser
import sys
def calculate_tuition(credits=12, nonresident=True, diff_tuition=False):
"""Calculates tuition and mandatory fees for one semester at UMD.
Takes into consideration the number of credits the student is taking,
whether they are a resident of Maryland, and whether they pay
differential tuition.
Args:
credits (integer): the number of credits the student is taking, defaulted to 12.
nonresident (boolean): whether the student is considered a Maryland state resident for tuition purposes, defaulted to True.
diff_tuition (boolean): whether or not the student pays differential tuition, defaulted to False.
Raises:
ValueError: credits must be non-negative.
Returns:
float: the student's combined tuition and mandatory fees.
"""
tuition = 0
if credits < 0:
raise ValueError("Number of credits can't be negative.")
if nonresident == False:
if credits >= 12:
tuition = 4412 + 977.50
elif credits >= 9:
tuition = 367*credits + 977.50
elif credits > 0:
tuition = 367*credits + 455
else:
return 0
else:
if credits >= 12:
tuition = 17468 + 977.50
elif credits >= 9:
tuition = 1456*credits + 977.50
elif credits > 0:
tuition = 1456*credits + 455
else:
return 0
if diff_tuition == True:
if credits >= 12:
tuition += 1428
else:
tuition += 118*credits
print(f"Credits is {credits}, nonresident of Maryland = {nonresident}, differential tuition = {diff_tuition}")
return tuition
def parse_args(arglist):
"""Parses command-line arguments.
The following optional command-line arguments are defined:
-c/--credits: the number of credits the student is taking
(type: int, default: 12)
-nr/--nonresident: indicates the student is not a Maryland
resident (action: 'store_true')
-dt/--differentialtuition: indicates the student pays differential
tuition (action: 'store_true')
Args:
arglist (list of str): a list of command-line arguments.
Returns:
namespace: a namespace with variables credits, nonresident, and
differentialtuition.
"""
parser = ArgumentParser()
parser.add_argument("-c", "--credits", type=int, default=12,
help="number of credits")
parser.add_argument("-nr", "--nonresident", action="store_true",
help="is Maryland resident")
parser.add_argument("-dt", "--differentialtuition", action="store_true",
help="has differential tuition")
return parser.parse_args(arglist)
if __name__ == "__main__":
args = parse_args(sys.argv[1:])
tuition = calculate_tuition(credits = args.credits, nonresident = args.nonresident, diff_tuition = args.differentialtuition)
print(f"Your tuition and fees total is ${tuition}")