-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (78 loc) · 2.63 KB
/
main.py
File metadata and controls
94 lines (78 loc) · 2.63 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
'''
Author: McSteve Ezikeoha
Title: Linked list database
Date: March 9, 2018
Description: You will write a command-line Python program keeps track of students in two different dimensions.
The purpose of this is to learn how to use linked lists and write code that manipulate them.
'''
import sys
import os
import traceback
import linkedlist
import MajorsList
import StudentRecord
def main():
majorslist = MajorsList.MajorsList()
alphalist = linkedlist.LinkedList()
while True:
try:
line = input(">> ")
if line == "quit":
break
elif line[0] == "#":
print(line)
elif line == "list majors":
majorslist.print_majors()
elif line.startswith("new major "):
the_new_major = line[10:]
if majorslist.find_major(the_new_major):
print("That major is already in the system!")
else:
majorslist.insert_sorted(the_new_major)
elif line.startswith("show major "):
the_major = line[10:]
stulisthead = majorslist.find_major(the_major)
if stulisthead is None:
print("No such major in the system!")
else:
majorslist.print_majors(the_major)
elif line.startswith("declare major "):
sturecptr = StudentRecord.StudentRecord(line[14:])
alphalist.insert_sorted(sturecptr)
majorslist.insert_student(sturecptr)
elif line == "list students":
alphalist.printList()
elif line.startswith("find "):
student_name = line[5:]
snode = alphalist.find(student_name)
if snode is None:
print("That student does not exist")
else:
snode.printAll()
elif line == "dump":
majorslist.dump()
elif line == "help":
print("list majors -- print the name of each major")
print("new major MAJORNAME -- add a new major to the system")
print("show major MAJORNAME -- list the students who have this major")
print("declare major NEWSTUDENT -- add a student to the system")
print(" the student info is: name,idnum,major,street,city,gpa")
print(" e.g. declare major Mark,1501,CSC,Main St.,Buffalo,3.614")
print("list students -- list all the students in alphabetical order regardless of major")
print("find NAME -- find a student with the NAME in the system and print their major")
print("dump -- write commands that would recreate the system")
print("help")
print("quit")
elif line.startswith("$"):
print(eval(line[1:]))
elif line.startswith("!"):
os.system(line[1:])
else:
print("Unknown command!")
except Exception as e:
tb = traceback.format_exc()
print("Caught a run-time error and recovered from it.")
print(e.__class__.__name__, end=", ")
print(e)
print(tb)
main()