-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentRecord.py
More file actions
62 lines (55 loc) · 1.65 KB
/
StudentRecord.py
File metadata and controls
62 lines (55 loc) · 1.65 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
class StudentRecord:
nextid = 1001
def __init__(self, *args):
if len(args) == 1:
if "," not in args[0]: #name only, rest are default values
self.name = args[0]
self.id = StudentRecord.nextid
StudentRecord.nextid += 1
self.major = "UND"
self.address = "Bosch Hall"
self.city = "Buffalo"
self.gpa = 0
else:
xargs = args[0].split(",")
if len(xargs) != 6:
print("****ERROR**** You need 6 args for the StudentRecord constructor")
else:
self.name = xargs[0]
self.id = int(xargs[1])
self.major = xargs[2]
self.address = xargs[3]
self.city = xargs[4]
self.gpa = float(xargs[5])
else:
if len(args) != 6:
print("**** ERROR **** You need 6 args for the StudentRecord constructor")
else:
self.name = args[0]
self.id = int(args[1])
self.major = args[2]
self.address = args[3]
self.city = args[4]
self.gpa = float(args[5])
def print(self):
print(self.name, self.major)
def printAll(self):
print("%-10s %s" % ("name:",self.name))
print("%-10s %d" % ("id:",self.id))
print("%-10s %s" % ("major:", self.major))
print("%-10s %s" % ("address:", self.address))
print("%-10s %s" % ("city:", self.city))
print("%-10s %5.3f" % ("gpa:",self.gpa))
print("")
def dump(self):
return self.name+","+str(self.id)+"," + self.major + "," + self.address + "," + self.city+ "," + str(self.gpa)
# more methods here
if __name__ == "__main__":
s1 = StudentRecord("Mark")
print(s1.dump())
s2 = StudentRecord("John,1501,CSC,Richmond Ave,Buffalo,4.000")
s2.dump()
s2.print()
s3 = StudentRecord("Mary", 1677, "HIS", "Main St", "Albany", 3.998)
s3.dump()
s3.printAll()