class teacher:
def __init__(self, data):
self.data = data
self.avg = []
for i in range(len(self.data)):
self.avg.append([self.data[i].name, self.data[i].average])
self.calcRank()
self.final()
# print('total data', self.data)
BUBBLESORT 사용법:
def calcRank(self):
for i in range(len(self.avg)-1):
for j in range(len(self.avg)-1):
if self.avg[j][1] < self.avg[j+1][1]:
t = self.avg[j]
self.avg[j] = self.avg[j+1]
self.avg[j+1] = t
def final(self):
여기는 PRINT 쓰는 이유가 무슨 에러가 났는지 확인해보기 위해서
print(len(self.avg), len(self.data))
print(self.avg)
print(self.data[0].name)
for i in range(len(self.avg)):
for j in range(len(self.data)):
# print(self.avg[i],self.data[j])
if self.avg[i][0] == self.data[j].name:
print (self.data[j].name, i+1)
break
class student:
def __init__(self, name, grade, korean, math, english):
self.name = name
self.grade = grade
self.korean = korean
self.math = math
self.english = english
self.calcSubject()
def helloTalk(self):
print(self.name, self.grade, self.korean, self.math, self.english)
print(self.total, self.average)
def calcSubject(self):
self.total = self.korean + self.math + self.english
self.average = (self.korean + self.math + self.english)/3
st1 = student ('Ashley', 3, 100, 100, 100)
st2 = student ('Emma', 5, 70, 80, 90)
st3 = student ('Tim', 6, 60, 97, 78)
st4 = student ('David', 4, 91, 99, 98)
st5 = student ('Chris', 2, 88, 45, 23)
classroom = []
classroom.append(st1)
classroom.append(st2)
classroom.append(st3)
classroom.append(st4)
classroom.append(st5)
선생님한테 데이터를 옮겨주기 위해서
t = teacher(classroom)
# bubbleSort = [['Ashley', 78], ['Chris', 24] , ['Tim', 55], ['Hi', 10]]
# for i in range(len(bubbleSort)-1):
# for j in range(len(bubbleSort)-1):
# if bubbleSort[j][1] > bubbleSort[j+1][1]:
# t = bubbleSort[j]
# bubbleSort[j] = bubbleSort[j+1]
# bubbleSort[j+1]= t
#
# print(bubbleSort)
# class student:
# def __init__(self, name, height):
# print('Here is Init')
# self.name = name
# self.height = height
# def calcu(self):
# print('calcu')
#
# classroom = []
# std1 = student('ike', 178)
# classroom.append(std1)
# std2 = student('Jelly', 150)
# classroom.append(std2)
#
# x = input()
#
# '''
# [0] name height def1 def2
# [1] ..
# [2] ...
# [3] ....
#
# '''
#
#
#
#
# import copy
#
# x = [1, 2, 3, 4, 5]
# y = x
# y = copy.deepcopy(x)
#
# print('before:', x, y)
#
# y[2] = 9
# print('After:', x, y)
DEEP COPY 활용법:
비교하는 법
# paper = [['a', 50], ['b', 100], ['c', 95], ['d', 60]]
#
# # deep copy
# readData = [['a', 50], ['b', 100], ['c', 95], ['d', 60]]
#
# for i in range(len(readData)-1):
# for j in range(len(readData)-1):
# if readData[j][1] < readData[j+1][1]:
# t = readData[j]
# readData[j] = readData[j+1]
# readData[j+1] = t
#
# print(readData)
#
# for i in range(len(readData)):
# for j in range(len(paper)):
# if readData[i][1] == paper[j][1]:
# print(paper[j][0], i+1)
# break
top of page
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
20230427
20230427
댓글 0개
좋아요
댓글(0)
bottom of page