-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpcalculator.py
More file actions
111 lines (82 loc) · 2.93 KB
/
gpcalculator.py
File metadata and controls
111 lines (82 loc) · 2.93 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
#! /usr/bin/python3
"""
This GPA application will help you calculate your
GP using 5.0 scale
"""
print(" ")
print(" Hi, Insert your course, grade and unit using this format :")
print("Example: MTH101,A,5 ")
print(" ")
print("************************************************************")
print("The System calculates the GP once you have inserted the")
print("grades for all the courses")
print("************************************************************")
print(" ")
def gpcalculator():
fullgrades=[]
units = 0
try:
total=0
try:
number= int(input("How many course did you offer? >> "))
except ValueError:
print ("It requires an integer")
for a in range(number):
stuff= (input(">> ")).upper()
course,grade,unit = stuff.split(',')
# courses.append(course)
# grades.append(grade)
units+=int(unit)
fullgrade = (course +" " +unit+" " + grade)
fullgrades.append(fullgrade)
if grade=="A" :
tot = 5 * int(unit)
total+=tot
elif grade=="B" :
tot = 4 * int(unit)
total+=tot
elif grade=="C" :
tot = 3 * int(unit)
total+=tot
print (tot)
print(total)
elif grade=="D" :
tot = 2 * int(unit)
total+=tot
elif grade=="E" :
tot = 1 * int(unit)
total+=tot
elif grade=="F" :
tot = 0 * int(unit)
total+=tot
else:
print ("Invalid Input. Check your input")
retry= input("Do you want to start again? y or n >>").lower()
if retry=="y" :
gpcalculator()
elif retry=="n" :
exit
else:
exit
print("************************************************************")
print("These are the courses, unit and grades you inserted :")
print(" ")
print("Courses Units Grades")
for each in fullgrades:
print (each)
gp =float(total/units)
print(" ")
print("************************************************************")
print ("Your GP is:%f "%(gp))
print("************************************************************")
print(" ")
except (NameError,ValueError ):
print ("Check what you inputted and try again")
retry= input("Do you want to start again? y or n >>").lower()
if retry=="y" :
gpcalculator()
elif retry=="n":
exit
else:
exit
gpcalculator()