p1/02_sikaniranje/naloga.py

37 lines
745 B
Python
Raw Normal View History

2023-10-27 10:49:52 +00:00
ovire = [(1, 3, 6), (2, 4, 3), (4, 6, 7), (3, 4, 9), (6, 9, 5), (9, 10, 2), (9, 10, 8)]
x = 6
min_y = None
for x1, x2, y in ovire:
if x >= x1 and x <= x2 and (min_y == None or min_y > y):
min_y = y
print(min_y)
# Dodatna naloga
ovire = [(1, 3, 6), (2, 4, 3), (4, 6, 7), (3, 4, 9), (6, 9, 5), (9, 10, 2), (9, 10, 8)]
sirina = 0
for x1, x2, y in ovire:
if x2 > sirina:
sirina = x2
max_x = 0
max_y = 0
for x in range(1, sirina+1):
min_y = None
for x1, x2, y in ovire:
if x >= x1 and x <= x2 and (min_y == None or min_y > y):
min_y = y
if min_y == None:
print(x, "Zmaga!")
break
if max_y < min_y:
max_y = min_y
max_x = x
else:
print(max_x, max_y)