This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
class Course(object): | |
id = None | |
limit_courses=3 | |
description = "" | |
name = "" | |
list = [] | |
enroll_list = dict() | |
@classmethod | |
def create(self, obj): | |
if len(self.list)==3: | |
print "Oops! Only 3 courses. Goodbye" | |
else: | |
try: | |
self.list.append(obj) | |
print self.list | |
except: | |
print "Sorry, PROBLEM!" | |
@classmethod | |
def print_all(self): | |
print "Courses: " | |
for x in self.list: | |
print x.id + " :::::::: " + x.name | |
@classmethod | |
def get_by_id(self, id): | |
for x in self.list: | |
try: | |
if x['id'] == id: | |
return x | |
except: | |
print "No found course" | |
class Person(object): | |
""" | |
Canonical person object | |
""" | |
name = "" | |
last_name = "" | |
address = "" | |
id = None | |
list = [] | |
@classmethod | |
def get_by_id(self, id): | |
for x in self.list: | |
if x['id'] == id: | |
return x | |
else: | |
print "No found" | |
@classmethod | |
def create(self, obj): | |
try: | |
self.list.append(obj) | |
print self.list | |
except: | |
print "Sorry, PROBLEM!" | |
@classmethod | |
def print_all(self): | |
print "List: " | |
for x in self.list: | |
print x.id + " :::::::: " + x.name | |
class Student(Person): | |
""" | |
It's a student object, from person | |
""" | |
pass | |
class Teacher(Person): | |
""" | |
It's a person object, from person | |
""" | |
pass | |
class Main(object): | |
if __name__ == "__main__": | |
ans=True | |
while ans: | |
print (""" | |
1.Create Course | |
2.Create Student | |
3.Create Teacher | |
4.Register Student to Course | |
5.Assign Teacher to Course | |
6.Print report | |
7.Exit | |
""") | |
ans=raw_input("What would you like to do? ") | |
if ans=="1": | |
print("\n Create Course") | |
ans_menu_course=True | |
while ans_menu_course: | |
print (""" | |
1.Math | |
2.Science | |
3.History | |
4.Exit/Quit | |
""") | |
ans_menu_course=raw_input("What course you want to create? ") | |
if ans_menu_course=="1": | |
description=raw_input("Enter course description: ") | |
id=raw_input("Enter course ID: ") | |
limit_students=raw_input("How many students? ") | |
c = Course() | |
c.name = "Math" | |
c.description = description | |
c.id = id | |
c.limit_students = limit_students | |
Course.create(c) | |
ans_menu_course=None | |
elif ans_menu_course=="2": | |
description=raw_input("Enter course description: ") | |
id=raw_input("Enter course ID: ") | |
limit_students=raw_input("How many students? ") | |
c = Course() | |
c.name = "Science" | |
c.description = description | |
c.id = id | |
c.limit_students = limit_students | |
Course.create(c) | |
ans_menu_course=None | |
elif ans_menu_course=="3": | |
description=raw_input("Enter course description: ") | |
id=raw_input("Enter course ID: ") | |
limit_students=raw_input("How many students? ") | |
c = Course() | |
c.name = "History" | |
c.description = description | |
c.id = id | |
c.limit_students = limit_students | |
Course.create(c) | |
ans_menu_course=None | |
elif ans_menu_course=="4": | |
sys.exit() | |
elif ans=="2": | |
print("\n :::::::: Create Student :::::") | |
ans_menu_student=True | |
while ans_menu_student: | |
name=raw_input("Name?: ") | |
last_name=raw_input("LastName?: ") | |
id=raw_input("ID?: ") | |
address=raw_input("Any Address?: ") | |
s = Student() | |
s.name = name | |
s.last_name = last_name | |
s.id = id | |
s.address = address | |
Student.create(s) | |
ans_menu_student=None | |
elif ans=="3": | |
print("\n :::::::: Create Teacher :::::") | |
ans_menu_teacher=True | |
while ans_menu_teacher: | |
name=raw_input("Name?: ") | |
last_name=raw_input("LastName?: ") | |
id=raw_input("ID?: ") | |
address=raw_input("Any Address?: ") | |
t = Teacher() | |
t.name = str(name) | |
t.last_name = str(last_name) | |
t.id = str(id) | |
t.address = str(address) | |
Teacher.create(t) | |
ans_menu_teacher=None | |
elif ans=="4": | |
print("\n :::::::: Register Student to Course :::::") | |
print(":::::::: please select the course :::::") | |
ans_menu_teacher=True | |
while ans_menu_teacher: | |
Course.print_all() | |
course_id=raw_input("\n Course ID?: ") | |
Course.get_by_id(course_id) | |
Student.print_all() | |
#ans_menu_teacher=None | |
elif ans=="5": | |
print("\n :::::::: Assign Teacher to Course :::::") | |
print(":::::::: please select the teacher :::::") | |
ans_menu_teacher=True | |
while ans_menu_teacher: | |
name=raw_input("Name?: ") | |
last_name=raw_input("LastName?: ") | |
id=raw_input("ID?: ") | |
address=raw_input("Any Address?: ") | |
t = Teacher() | |
t.name = str(name) | |
t.last_name = str(last_name) | |
t.id = str(id) | |
t.address = str(address) | |
Teacher.create(t) | |
ans_menu_teacher=None | |
elif ans=="6": | |
Course.print_all() | |
elif ans=="7": | |
print("\n Goodbye") | |
sys.exit() | |
elif ans !="": | |
print("\n Not Valid Choice Try again") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment