관리 메뉴

moozi

12/05 파이썬 성적처리 with 클래스 본문

TIS_2020/빅데이터분석주말반

12/05 파이썬 성적처리 with 클래스

moozi 2020. 12. 5. 10:22
scores=[]
class Student:
     def __init__(self, name, english, math, science):
         self.name = name
         self.english = english
         self.math=math
         self.science=science
     def calcAvg(self):
         total = int(self.english) + int(self.math) + int(self.science)
         self.avg = round(total / 3, 2)

while True:
    print("===============")
    print("등록 : 1  - 등록중 종료 :quit")
    print("목록 : 2")
    print("종료 : 0")
    print("===============")
    menu=input("menu : ");
    if menu=="1":
        name=input("이름을 입력하세요 : ")
        if (name == "quit"): break
        english=input("영어점수를 입력하세요 : ")
        if (english == "quit"): break
        math=input("수학점수를 입력하세요 : ")
        if (math == "quit"): break
        science=input("과학점수를 입력하세요 : ")
        if (science == "quit"): break
        s = Student(name,english,math,science)  #생성자호출.객체생성.멤버변수값초기화
        s.calcAvg() #평균구함
        scores.append(s)
        print("평균 : "+ str(s.avg))
        f = open("C:/doit/data.txt", 'a')
        f.write(str(s.name))
        f.write("," + str(s.english))
        f.write("," + str(s.math))
        f.write("," + str(s.science))
        f.write("," + str(s.avg) + "\n")
        f.close()
    elif menu=="2":
        f2 = open("C:/doit/data.txt", 'r')
        data = f2.read()
        print(data)
        f2.close()
    else:
        break

'TIS_2020 > 빅데이터분석주말반' 카테고리의 다른 글

12/05 8월최고기온 히스토그램  (0) 2020.12.05
통계기초정리  (0) 2020.12.05
hadoop 참고  (0) 2020.12.05
11/28 seoul.csv  (0) 2020.11.28
11/28 최저기온  (0) 2020.11.28
Comments