วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558

Lab Raspberry pi - Python Grade

class Student:
    def __init__(self,name,idnum,score):
        self.name = name
        self.id = idnum
        self.score = score

# get method
    def get_id(self):
        return self.idnum
    def get_score(self):
        return self.score

#set method
    def set_score(self,value):
        self.score = value
       
#display mathod
    def display_info(self):
        print("Name :", self.name)
        print("ID :", self.id)
        print("Score :", self.score)

def show_all(student):
    i = 0
    while i<len(student):
        print("Grade",find_grade(student[i]))
        student[i].display_info()
        print()
        i = i + 1
           

def show_grade(student):
    i = 0
    while i<len(student) :
        print("Grade = ",find_grade(student[i]))
        i = i+1

def count_grade(student):
 
    i = 0
    a = 0
    b = 0
    c = 0
    d = 0
    f = 0
 
    while i<len(student) :
        if find_grade(student[i]) == "A":
            a = a + 1
        elif find_grade(student[i]) == "B":
            b = b + 1
        elif find_grade(student[i]) == "C":
            c = c + 1
        elif find_grade(student[i]) == "D":
            d = d + 1
        elif find_grade(student[i]) == "F":
            f = f + 1
        i = i + 1
    print("There is", a, "people have grade A")
    print("There is", b, "people have grade B")
    print("There is", c, "people have grade C")
    print("There is", d, "people have grade D")
    print("There is", f, "people have grade E")
         

def find_grade(student):
 
    score = student.get_score()
    if(score<50):
        return "F"
    elif(score<60):
        return "D"
    elif(score<70):
        return "C"
    elif(score<80):
        return "B"
    else :
        return "A"

def setup():
    student = [ Student("Nut",50001, 99),
                Student("Fok",50002, 49),
                Student("Gase",50003, 75),
                Student("Pee", 50004, 68),
                Student("Mind", 50005, 55)]
    show_grade(student)
    print()
    count_grade(student)
    print()
    show_all(student)
         
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น