#리스트 list [] 여러 개의 값을 묶어서 저장하는 자료형
list1 = [1, 2, 'a', '가', [7, 8]]

#리스트 인덱싱 : 리스트[인덱스 번호]
print(list1[0])
print(list1[-1])
print(list1[-1][1]) #중첩 인덱싱

#리스트 슬라이싱 : 리스트[시작:끝]
                # 리스트[시작:끝:칸step]
print(list1[0:4:2])
print(list1[::-1])

#리스트 원소 바꾸기
#리스트[인덱스] = 새로운 자료
list1[2] = 'apple'
print(list1)

#리스트 메서드
print(sum([1, 2, 3]))
print(len(list1))

#리스트.append(추가할 원소)  : 리스트 맨 뒤에 추가
a = [1, 2, 3]
a.append(4)
print(a)

#리스트.insert(추가할 위치, 추가할 원소)  : 원하는 위치에 추가
a.insert(2, 'a')
print(a)

#리스트.remove(삭제할 원소)
b = [3, 1, 2, 3]
b.remove(3)
print(b)

#리스트.sort()
c = [3, 1, 5, 8, 4, 6, 1, 2, 9]
c.sort() #오름차순
print(c)

d = ['나', '마', '다', 'a', 'c', '이', '가']
d.sort() #사전순
print(d)

print('----문제1----')
scores = [75, 100, 82, 90, 68, 88]
#1. 오름차순 정렬
scores.sort()
print(scores)

#2. 최고 점수와 최저 점수 출력
high = scores[-1]
low = scores[0]
print('최저 점수 : ', low)
print('최고 점수 : ', high)
print(max(scores)) #max() 괄호 안 자료형 중 최대값
print(min(scores)) #min() 괄호 안 자료형 중 최솟값

#3. 최고 점수와 최저 점수 제거
scores.remove(low)
scores.remove(scores[-1])
print('최고, 최저 제거 후', scores)

#4. 남은 점수의 평균 계산
average = sum(scores) / len(scores)
print('평균 :', average)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: