실습문제 1.
import random
random_list = random.sample(range(1,101),10)
evens= [x for x in random_list if x%2 ==0]
odds= [x for x in random_list if x%2 !=0]
if evens and odds:
max_even =max(evens)
max_odd=max(odds)
max_sum=max_even+max_odd
result_pair = [max_even, max_odd]
print(result_pair)
print(max_sum)
else:
print("NONE")
실습문제 2.
# -*- coding: utf-8 -*-
# 점 리스트
points = [(0, 0), (-1, -1), (4, 2), (2, -3), (6, 7), (8, 4), (12, -2)]
# 모든 세 점 조합을 확인하고, 일직선에 있으면 출력
for i in range(len(points)):
for j in range(i + 1, len(points)):
for k in range(j + 1, len(points)):
# 세 점이 일직선 상에 있는지 확인
if (points[j][1] - points[i][1]) * (points[k][0] - points[i][0]) == (points[k][1] - points[i][1]) * (points[j][0] - points[i][0]):
print(points[i], points[j], points[k])
이론문제1.
이론문제2.