Example #1
0
def main():

    # Create a dictionary to hold mammal and student
    # Numbered keys is the way.
    stud_pet_dic = dict()
    # Create a list to hold both student and mammal object
    stud_pet_lst = []

    # Create both objects and store them into the
    # empty list as a separate list, for convenience
    myself = Student("Tapio", "Koskinen", 1337)
    mypet = Mammal(1, "Bear", "Tiny", "Big", 150, 2)
    stud_pet_lst.append([myself, mypet])

    friend = Student("Matti", "Mallikas", 100)
    friendpet = Mammal(2, "Unicorn", "Fred", "Medium", 500, 1.5)
    stud_pet_lst.append([friend, friendpet])

    # Add each pair that is in the pair list
    for i in range(len(stud_pet_lst)):
        stud_pet_dic[i] = stud_pet_lst[i]

    # Loop through all key in the dictionary
    # and print out the student and their pet
    for i in stud_pet_dic:
        pair = stud_pet_dic[i]
        print("*" * 40)
        print(f"Student:\n\n{pair[0]}\n" + "-" * 30,
              f"\nHis/her pet:\n\n{pair[1]}")

    print("*" * 40)
Example #2
0
 def test_invalid(self):
     s1 = Student('Bart', -1)
     s2 = Student('Lisa', 101)
     with self.assertRaises(ValueError):
         s1.get_grade()
     with self.assertRaises(ValueError):
         s2.get_grade()
    def show_student_info(self, roll_no):
        try:
            cursor = self.connection.cursor(dictionary=True)

            SEARCH_STUDENT_QUERY = f'''
            SELECT * FROM {self.TABLE_NAME} WHERE roll_no = "{roll_no}"
            '''

            cursor.execute(SEARCH_STUDENT_QUERY)
            row = cursor.fetchone()

            if (row != None):
                return Student(
                    roll_no=row["roll_no"],
                    name=row["name"],
                    address=row["address"],
                    contact=row["contact"],
                    city=row["city"],
                    standard=row["standard"],
                )
            else:
                return None

        except mysql.connector.Error as e:
            print(f'error  :  {e}')
            return None

        finally:
            cursor.close()
    def show_all_students(self):
        try:
            cursor = self.connection.cursor(dictionary=True)

            SEARCH_ALL_STUDENT_QUERY = f'''
            SELECT * FROM {self.TABLE_NAME}             '''

            cursor.execute(SEARCH_ALL_STUDENT_QUERY)
            rows = cursor.fetchall()

            if (len(rows)):
                for row in rows:
                    Student(
                        roll_no=row["roll_no"],
                        name=row["name"],
                        address=row["address"],
                        contact=row["contact"],
                        city=row["city"],
                        standard=row["standard"],
                    ).show()
            else:
                print("No students in database")

        except mysql.connector.Error as e:
            print(f'error  :  {e}')

        finally:
            cursor.close()
Example #5
0
def input_student():
    L = []
    while True:
        name = input("姓名:")
        if not name:
            break
        age = int(input("年龄:"))
        score = int(input("成绩:"))
        d = Student(name, age, score)
        L.append(d)
    return L
Example #6
0
def add():
    roll_no = input("Enter roll_no: ")
    name = input("Enter name: ")
    address = input("Enter address: ")
    contact = input("Enter contact: ")
    city = input("Enter city: ")
    standard = input("Enter standard: ")
    student = Student(roll_no=roll_no,
                      name=name,
                      address=address,
                      contact=contact,
                      city=city,
                      standard=standard)
    database.insert_student(student)
Example #7
0
def sample_data():
    sample_list = [{
        "roll_no": "1",
        "name": "annant",
        "address": "454446",
        "contact": "9806",
        "city": "manawar",
        "standard": "1"
    }, {
        "roll_no": "2",
        "name": "shyam",
        "address": "380069",
        "contact": "0990",
        "city": "kolkata",
        "standard": "2"
    }, {
        "roll_no": "3",
        "name": "akshita",
        "address": "452010",
        "contact": "9179",
        "city": "indore",
        "standard": "3"
    }, {
        "roll_no": "4",
        "name": "jay",
        "address": "656664",
        "contact": "7644",
        "city": "ahmedabad",
        "standard": "4"
    }, {
        "roll_no": "5",
        "name": "anna",
        "address": "452020",
        "contact": "7000",
        "city": "indore",
        "standard": "5"
    }]
    for student in sample_list:
        database.insert_student(
            Student(roll_no=student["roll_no"],
                    name=student["name"],
                    address=student["address"],
                    contact=student["contact"],
                    city=student["city"],
                    standard=student["standard"]))
Example #8
0
def read_info(filename='si.txt'):
    # 方法1:
    # try:
    # 	f = open(filename,'rt')
    # 	s = f.read()
    # 	print(s)
    # 	f.close()
    # except OSError:
    # 	print('读取文件失败')
    # 方法2:
    L = []
    try:
        f = open(filename, 'rt')
        for line in f:
            s = line.rstrip()
            name, age, score = s.split(',')
            age = int(age)
            score = int(score)
            L.append(Student(name, age, score))

        f.close()
    except OSError:
        print('读取文件失败')
    return L
Example #9
0
 def test_0_to_60(self):
     s1 = Student('Bart', 0)
     s2 = Student('Lisa', 59)
     self.assertEqual(s1.get_grade(), 'C')
     self.assertEqual(s2.get_grade(), 'C')
Example #10
0
 def test_60_to_80(self):
     s1 = Student('Bart', 60)
     s2 = Student('Lisa', 79)
     self.assertEqual(s1.get_grade(), 'B')
     self.assertEqual(s2.get_grade(), 'B')
Example #11
0
 def setUp(self):
     self.stud = Student('Rickels', 'Alex', 'Econ')
Example #12
0
 def test_object_not_created_error_gpa(self):
     with self.assertRaises(ValueError):
         student = Student('Rickels', 'Alex', 'Econ', 'four point o')
Example #13
0
 def test_object_not_created_error_major(self):
     with self.assertRaises(ValueError):
         student = Student('Rickels', 'Alex', '457')
Example #14
0
 def test_object_not_created_error_first_name(self):
     with self.assertRaises(ValueError):
         student = Student('Rickels', '63', 'Econ')
Example #15
0
 def test_object_not_created_error_last_name(self):
     with self.assertRaises(ValueError):
         student = Student('45', 'Alex', 'Econ')
Example #16
0
 def test_object_created_all_attributes(self):
     studenta = Student('Rickels', 'Alex', 'Econ', 4.0)
     assert studenta.last_name == 'Rickels'
     assert studenta.first_name == 'Alex'
     assert studenta.major == 'Econ'
     assert studenta.gpa == 4.0
from student_class import Student
from student_school import School
from student_subjects import Subject
from mysql_function import insertSchoolTodb
from mysql_function import insertStudentTodb
from mysql_function import getStudentId
from mysql_function import insertSubjectTodb
from grades_printer import getSubjects

allstudents = [] #for storing all student objects in a list

NoOfstudents = int(input('Enter number of students :'))
for x in range(0,NoOfstudents):
    name = input('Enter student name :')
    regNumber = int(input('Enter registration number :'))
    student = Student(name,regNumber)
    #insert student into database
    insertStudentTodb(student)

    schoolId = input('Enter school id :')
    schoolname = input('Enter school name :')
    schoolAddress = input('Enter school schoolAddress :')
    schoolCode = input('Enter school code :')
    studentID = getStudentId(student)
    school = School(schoolname,schoolAddress,schoolCode,studentID)
    
    #insert school into database
    insertSchoolTodb(school)
    
    NoOfsubjects = int(input('Enter number of subjects :'))
    
Example #18
0
from student_class import Student, WorkingStudent

# Instances of class Student

fabio = Student('Fabio Lima', 'UNIPE')
print(fabio.school)
fabio_lima = WorkingStudent('Fabio Lima', 'UNIPE', 2700)
print(fabio_lima.salary)
Example #19
0
    option = input("\nEntry: ")

    try:
        option = int(option)
    except ValueError:
        print("Incorrect entry.\n")
        continue

    if option == 0:
        print("Thank you, goodbye")
        sys.exit()

    elif option == 1:
        f_name = input("Enter first name: ")
        l_name = input("Enter last name: ")
        student_list.append(Student(f_name, l_name))
        print("Successful. {} {} added.".format(student_list[-1].get_f_name(),
                                                student_list[-1].get_l_name()))

    elif option == 2:
        f_name = input("Enter first name: ")
        l_name = input("Enter last name: ")
        teacher_list.append(Teacher(f_name, l_name))
        print("Successful, {} {} added. ID - {}".format(
            teacher_list[-1].get_f_name(), teacher_list[-1].get_l_name(),
            len(teacher_list)))

    elif option == 3:
        ws_id = input("Enter class name: ")
        t_id = int(input("Enter teacher ID number: ")) - 1
        workshop_list.append(
Example #20
0
    "contact": "7644",
    "city": "ahmedabad",
    "standard": "4"
}, {
    "roll_no": "5",
    "name": "anna",
    "address": "452020",
    "contact": "7000",
    "city": "indore",
    "standard": "5"
}]

for elem in sample_list:
    student = Student(roll_no=elem["roll_no"],
                      name=elem["name"],
                      address=elem["address"],
                      contact=elem["contact"],
                      city=elem["city"],
                      standard=elem["standard"])
    database.append(student)

# for student in database:
#     student.show()

# student = database[0]
# student.update("aaa")
# student.show()


def add():
    roll_no = input("Enter roll_no: ")
    name = input("Enter name: ")
Example #21
0
#importing student_class file and also importing student class
from student_class import Student

Student_obj = Student("ashwin", 23012322, 23, "BE", 7)

print(Student_obj.gpa)
Example #22
0
 def test_80_to_100(self):
     s1 = Student('Bart', 80)
     s2 = Student('Lisa', 100)
     self.assertEqual(s1.get_grade(), 'A')
     self.assertEqual(s2.get_grade(), 'A')
Example #23
0
from student_class import Student

student1 = Student("George", "7", 3.1, False)
student2 = Student("Pam", "8", 1.1, True)
print(student2.gpa)
Example #24
0
def getSubjects():
    myconnection = myDatabaseConnector()
    mycursor = myconnection.cursor()
    students_query = "select * from students;"
    mycursor.execute(students_query)
    studentresults = mycursor.fetchall()

    #fetch one by one student
    all_school_subjects = []
    for one_student in studentresults:
        #create instance of student object
        student = Student(one_student[0], one_student[1])
        studid = one_student[2]
        print('Name :{}\nRegNo :{}\nStudent Id :{}'.format(
            student.name, student.regNumber, studid))

        #fetch individual student subjects

        #print subjects
        print('\n======Subjects===== \n')

        get_subject_id = "select * from subjects where student_id=%s;"
        new_studId = (studid, )
        mycursor.execute(get_subject_id, new_studId)
        subject_results = mycursor.fetchall()

        #get single subject information and assign to subjects object

        all_student_subjects = []

        for single_subject in subject_results:

            #assign Subject object to single_subject

            subject = Subject(single_subject[0], single_subject[1],
                              single_subject[2])

            #print single subject details

            print('{}:{} Grade:{}'.format(subject.subjectName,
                                          subject.subjectScore,
                                          gradingSystem(subject.subjectScore)))
            all_student_subjects.append(subject.subjectScore)

            #add subjects score to all_school_subjects

            all_school_subjects.append(subject.subjectScore)

        #get mean score and mean grade for all subjects

        NoOfSubjects = len(all_student_subjects)
        totalMarks = sum(all_student_subjects)
        meanScore = getMean(totalMarks, NoOfSubjects)
        meanGrade = gradingSystem(meanScore)
        print('Mean Score :{}'.format(meanScore))
        print('Mean Grade :{}'.format(meanGrade))
        print('___________________________\n')

    #grab all all_school_subjects_scores

    NoOfSchool_Subjects = len(all_school_subjects)
    totalSchoolMarks = sum(all_school_subjects)
    schoolMeanScore = getMean(totalSchoolMarks, NoOfSchool_Subjects)
    schoolMeanGrade = gradingSystem(schoolMeanScore)

    print('===Overall School Perfomance===')

    print('Mean Score for the school is :{}'.format(schoolMeanScore))
    print('Mean Grade for the school is :{}'.format(schoolMeanGrade))


#getSubjects() for testing purposes
Example #25
0
from functools import reduce
from student_class import Student

students = []
with open("student_try.csv", "r", encoding='utf8') as file:
    for line in file:
        students.append(Student(line))

students.sort(key=lambda stu: stu.score, reverse=True)
m = map(lambda stu: stu.make_grade(), students)
list(m)

total = reduce(lambda x, y: (x if type(x) == int else x.score) + y.score,
               students)
avg = total / len(students)
print("총계, 평균 >", total, avg)

print("이름\t성별\t나이\t학점")
print("----\t----\t----\t----")

for s in students:
    print(s)

print("이름\t점수")
print("------\t----")

for s in students:
    if s.score >= avg:
        print("{}\t{}".format(s.name, s.score))