Language/Python
예제) 사각형 넓이 구하기
developerBeluga
2021. 4. 2. 10:57
728x90
반응형
조건:
사각형의 밑변 width와 높이 height를 input 함수를 사용하여 키보드로 부터 입력받아,
사각형의 넓이를 계산하는 calRectangleArea함수를 작성하시오.
조건, while문을 이용하여 반복하여 계산하게 하고 종료 조건은 입력된 width가 -1이면 반복문을 빠져 나옵니다.
|
1
2
3
4
5
6
7
8
9
|
def calRectangleArea(width, height):
return width * height
while(True):
width = int(input("너비를 입력하세요 : "))
if width == -1: break
height = int(input("높이를 입력하세요 : "))
print("사격형의 넓이 : ", calRectangleArea(width, height))
print("계산을 종료합니다")
|
cs |
너비와 높이를 동시에 받는 경우
1 2 3 4 5 6 7 8 | def calRectangleArea(width, height): return width * height while(True) : width, height = input('너비와 높이를 입력하시오.').split() if int(width) == -1: print('프로그램을 종료합니다.') break print(calRectangleArea(int(width), int(height))) | cs |
728x90
반응형