forked from drycode/zelle-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_6.py
58 lines (47 loc) · 1.58 KB
/
exercise_6.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
class Student:
def __init__(self, name, hours, qpoints):
self.name = name
self.hours = float(hours)
self.qpoints = float(qpoints)
def getName(self):
return self.name
def getHours(self):
return self.hours
def getQPoints(self):
return self.qpoints
def gpa(self):
return self.qpoints / self.hours
def addGrade(self, gradePoint, credits):
self.hours = float(self.hours) + float(credits)
self.qpoints = self.qpoints + (gradePoint * credits)
def addLetterGrade(self, letterGrade, credits):
self.letterGrade = letterGrade
if self.letterGrade == "A":
gradePoint = 4
elif self.letterGrade == "B":
gradePoint = 3
elif self.letterGrade == "C":
gradePoint = 2
elif self.letterGrade == "D":
gradePoint = 1
else:
gradePoint = 0
self.hours = float(self.hours) + float(credits)
self.qpoints = self.qpoints + (gradePoint * credits)
def makeStudent(infoStr):
#inforStr is a tap-separated line: name hours getQPoints
#returns a corresponding Student object
name, hours, qpoints = infoStr.split("\t")
return Student(name, hours, qpoints)
def main():
new = makeStudent("Smith, Frank 0 0")
x = input("Input gradepoint OR letter grade. ")
y = eval(input("Input credit hours. "))
if x.isdigit() == True:
x = eval(x)
new.addGrade(x, y)
else:
new.addLetterGrade(x.upper(), y)
print(new.getHours(), new.getQPoints())
print(new.gpa())
main()