아래의 패턴들을 if문 없이 for문과 range, print만을 사용하여 출력하기.
단, print문은 소스 코드에서 (한 패턴당) 한번만 사용할 수 있음.
1번 패턴
*
**
***
****
*****
2번 패턴
*
**
***
****
*****
3번패턴
*****
****
***
**
*
4번패턴
*****
****
***
**
*
for문과 if문과 continue문을 사용하여 작성하는 경우는 continue의 사용법을 체크하는 경우이고,
이 경우는 f-string에 대한 이해를 확인하는 문제임.
for i in range(1,6):
a = '*'*i
t = f'>5s'
print(f'{a:{t}}')
for i in range(1,6):
a = '*'*i
t = f'<5s'
print(f'{a:{t}}')
for i in range(5,0,-1):
a = '*'*i
t = f'<5s'
print(f'{a:{t}}')
for i in range(5,0,-1):
a = '*'*i
t = f'>5s'
print(f'{a:{t}}')
참고자료
https://dsaint31.tistory.com/532
[Python] f-String
Python : f-StringPython 3.6 이후 도입됨.기존의 중괄호 {}과 format 메소드를 사용하여 문자열 포매팅을 설정하는 방식(Python 2.6 이후)과 유사하지만, 더 직관적으로 문자열을 포맷팅할 수 있는 기능으로
dsaint31.tistory.com
https://dsaint31.tistory.com/573
[Python] for statement
for statement는 loop를 위한 control structure의 대표격이다. Python에서는 iterable 객체 (주로 collection type의 객체들)이 가지고 있는 item들을 iterate하는 용도로 사용된다. 프로그래밍을 배울 때, 구구단 출력
dsaint31.tistory.com
https://dsaint31.tistory.com/502
[Python] range and enumerate
엄밀하게 애기하면, range 는 숫자들의 immutable sequence를 나타내는 built-in type이다. 즉, 흔히 built-in function으로 애기하는 range() 는 사실은 range class의 instance를 생성하는 생성자에 해당한다. sequence
dsaint31.tistory.com
'Python' 카테고리의 다른 글
[NumPy] 생성 및 초기화, 기본 조작 (1) (0) | 2024.09.09 |
---|---|
[Py] Python에서 string formatting. (0) | 2024.09.04 |
[Python] Class 간단 정리 (0) | 2024.07.24 |
[Python] 사용자와 상호작용: 입력받기: input, argv, and sys (0) | 2024.07.24 |
[Programming] Binding: Name Binding and Language Binding (0) | 2024.06.06 |