본문 바로가기

개발일지/TIL

TIL 23-03-23

https://github.com/sdoram/Algorithm_study

 

GitHub - sdoram/Algorithm_study: 알고리즘 문제 풀이

알고리즘 문제 풀이. Contribute to sdoram/Algorithm_study development by creating an account on GitHub.

github.com

1. 프로그래머스 알고리즘 문제 - 직각삼각형 출력하기 

 문제점

*을 역순으로 출력하는데 뒤집어서 출력할 방법을 모름

n = int(input())
while n > 0:
    print(n * '*')
    n -= 1

 시도해 본 것들

count 라는 변수를 선언하고 숫자를 하나씩 더 하기

 해결 방법

# 내 해결방법
n = int(input())
count = 0
while count < n:
    count += 1
    print(count * '*')
# 팀원들의 방식으로 내가 작성한 코드 
n = int(input())
for i in range(1, n + 1):
    print('*' * i)

알게 된 점

while문을 사용하면서 추가적인 변수 선언을 하지 않고, for문과 range를 이용하면 코드를 깔끔하게 작성할 수 있다.

 

 

 

'개발일지 > TIL' 카테고리의 다른 글

TIL 23-03-25  (0) 2023.03.25
TIL 23-03-24  (1) 2023.03.24
TIL 23-03-22  (2) 2023.03.22
TIL 23-03-21  (0) 2023.03.21
TIL 23-03-20  (0) 2023.03.20