제로베이스 데이터 취업 스쿨 - 19일차(6/20)

수야·2023년 6월 20일
0

자료구조란?



튜플은 한번 정해진 내용은 바꿀 수 없는 자료형
set은 중복된 내용이 없는 숫자 자료형

리스트(List)


리스트 아이템 조회


실습

students = ['김성예','신경도','박기준','최승철','황동석']

print('--인덱스가 짝수인 학생 --')

for i in range(len(students)):
    if i % 2 == 0 :
        print(f'students[{i}] : {students[i]}')

print('--인덱스가 홀수인 학생 --')

for i in range(len(students)):
    if i % 2 != 0 :
        print(f'students[{i}] : {students[i]}')

리스트 길이



for 또는 while

실습

favSport = ['수영','배구','야구','조깅']

for i in range(len(favSport)) :
    print(f'myFavSport [{i}] : {favSport[i]}')

리스트와 for문 (01)


실습

studentCnt = [[1,18],[2,19]]
count = 0
sumStudnet = 0
averStudent = 0
for classNO, students in studentCnt :
    print(f'{classNO}학습 학생 수 : {students}')
    count +=1
    sumStudnet += students
averStudent = int(sumStudnet/count)
print(f'전체 학생 수 : {sumStudnet}명')
print(f'평균 학생 수 : {averStudent}명')

리스트와 for문 (02)


실습

minscore = 60
kor = int(input('국어점수입력'))
eng = int(input('영어점수입력'))
math = int(input('수학점수입력'))

scoreList = [['kor', kor], ['eng', eng],['math', math]]

for subject, score in scoreList:
    if score < minscore :
        print(f'{subject} 과락! 점수 :{score}, 기준 : {minscore}')

실습

리스트와 while문(01)


실습

studentList = [[1,18],[2,19],[3,23]]

sum = 0
count = 0
average = 0
n = 0
while n < len(studentList) :
    classNo = studentList[n][0]
    studnetNo = studentList[n][1]
    sum += studnetNo
    count += 1
    n += 1
    print(f'{classNo}학급 학생수 : {studnetNo}')
    continue
print(f'전체 학급 학생수 {sum}')
average =int(sum/count)
print(f'전체 학급 평균 학생 수 {average}')

리스트와 while문 (02)


실습

minScore = 60
kor = int(input('kor'))
eng = int(input('eng'))
math = int(input('math'))
science = int(input('science'))
history = int(input('history'))

scoreList  = [
    ['kor', kor],
    ['eng', eng],
    ['math', math],
    ['science', science],
    ['history', history]
              ]

n = 0

while n <len(scoreList):
    subject = scoreList[n][0]
    score = scoreList[n][1]
    if scoreList[n][1] < minScore:
        print(f'{subject}의 점수 {score}는 {minScore}보다 작기 때문에 과락')
    n += 1
    continue
    

실습

clasList = [
    [1, 18],
    [2, 19],
    [3, 23]]

maxStudent = 0
minStudent  = 0
maxClass = 0
minClass = 0
n = 1

while n < len(clasList) :
    if minStudent == 0 or minStudent > clasList[n][1]:
        minStudent = clasList[n][1]
        minClass = clasList[n][0]
    if maxStudent == 0 or maxStudent < clasList[n][1]:
        maxStudent = clasList[n][1]
        maxClass = clasList[n][0]
    n+=1
    continue


print(f'학생 수가 가장 적은 학급 : {minClass}학급({minStudent}명)')
print(f'학생 수가 가장 많은 학급 : {maxClass}학급({maxStudent}명)')
![](https://velog.velcdn.com/images/softwater/post/07bca74b-2c9f-401b-b6ae-6c19e420a730/image.png)
profile
수야는 코린이에서 더 나아갈거야

0개의 댓글