-
#20 in_range30 seconds of Code 2022. 2. 8. 23:56
https://www.youtube.com/watch?v=D4ygwp-PhQM&list=PLGPF8gvWLYypxQkVa1mXGn3td5wX2F-3L&index=20
def in_range(n, start, end): print(start <= n and n <= end) in_range(3, 2, 5) #True in_range(2,3,5) #False
이렇게 해도 주어진 문제는 맞았지만, 조건들을 많이 빼먹었다.
end값이 주어지지 않으면 end는 0이되고, end부터 start사이에 n이 존재하는지를 확인한다.
이 조건을 넣어서 다시 코드를 짜봤다.
def in_range(n, start, end=0): if start >= end: print(end <= n <= start) else : print(start <= n and n <= end)
반응형'30 seconds of Code' 카테고리의 다른 글
initialize_list_with_range (0) 2022.02.13 has_duplicates (0) 2022.02.08 filter_non_unique (0) 2022.02.08 왼손코딩 1일1파이썬 9,10,11,12 (0) 2022.02.04 [python]count_occurrences /degrees_to_rads/*difference (0) 2022.02.04