# 243p
#range(a, b, c) 위의 형태로 쓰면 a부터 b-1까지 c만큼 건너뛰는 수를 뜻한다.
# 예를들면 range(0, 50, 5) 라고 했을 때 0, 5, 10, 15....45 를 뜻한다고 생각하면 된다.
# 선의 개념으로 접근해보기
# ----n--------------t t+1---- 올라갈 때, [for i in range(n, t+1, +1)]
# ---t, t-1 -----------n--- 내려갈 때, [for i in range(n, t-1, -1)]
def goDownfloor(now, target):
for floor in range(now, target-1, -1):
print('현재 층은', floor, '입니다.')
print(target, '층에 도착하였습니다. 안녕히 가세요.')
def goUpfloor(now, target):
for floor in range(now, target+1, +1):
print('현재 층은', floor, '입니다.')
print(target, '층에 도착하였습니다. 안녕히 가세요.')
inputLocation = int(input('사용자가 가고자 하는 층을 입력하시오.'))
nowLocation = int(input('사용자가 있는 층을 입력하시오.'))
if ((inputLocation == nowLocation) or (inputLocation < 1) or (inputLocation > 6)):
print('다른 층(1~6)을 눌러주세요.')
# if-elif-elif로 가지 않고, if-else(if-else)로 가야하는 경우 생각해보기
# if-elif-elif (A=B=C, 동등한 관계여야 한다.)
else:
if (inputLocation <= nowLocation ):
goDownfloor(nowLocation, inputLocation)
else:
goupfloor(nowLocation, inputLocation)
'프로그래밍 공부' 카테고리의 다른 글
함수활용 실습문제 11-17, 노래음량, 에코, 템포조절 (0) | 2020.10.24 |
---|---|
함수활용 실습문제 11-14, 계산기 프로그램 (0) | 2020.10.23 |
16. Python, CheckiO Elementary_Is Even (0) | 2020.10.22 |
15. Python, CheckiO Elementary_Correct Sentence (0) | 2020.10.22 |
*14. Python, CheckiO Elementary_Between Markers (simplified) (1) | 2020.10.22 |
댓글