티스토리 뷰
Alphabet Rangoli
You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)
Different sizes of alphabet rangoli are shown below:
#size 3
----c----
--c-b-c--
c-b-a-b-c
--c-b-c--
----c----
#size 5
--------e--------
------e-d-e------
----e-d-c-d-e----
--e-d-c-b-c-d-e--
e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e--------
#size 10
------------------j------------------
----------------j-i-j----------------
--------------j-i-h-i-j--------------
------------j-i-h-g-h-i-j------------
----------j-i-h-g-f-g-h-i-j----------
--------j-i-h-g-f-e-f-g-h-i-j--------
------j-i-h-g-f-e-d-e-f-g-h-i-j------
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
------j-i-h-g-f-e-d-e-f-g-h-i-j------
--------j-i-h-g-f-e-f-g-h-i-j--------
----------j-i-h-g-f-g-h-i-j----------
------------j-i-h-g-h-i-j------------
--------------j-i-h-i-j--------------
----------------j-i-j----------------
------------------j------------------
The center of the rangoli has the first alphabet letter a, and the boundary has the N^th alphabet letter (in alphabetical order).
Function Description
Complete the rangoli function in the editor below.
rangoli has the following parameters:
- int size: the size of the rangoli
Returns
- string: a single string made up of each of the lines of the rangoli separated by a newline character (\n)
Input Format
Only one line of input containing size, the size of the rangoli.
Constraints
Sample Input
5
Sample Output
--------e--------
------e-d-e------
----e-d-c-d-e----
--e-d-c-b-c-d-e--
e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e--------
문제해석
랑골리(rangoli)라는 것은 인도 전통 미술로 집 마당이나 거실의 바닥을 전통 문양으로 장식하는 것이라고 한다. input으로 N값을 입력받아 알파벳으로 이 랑골리 패턴을 출력해야 한다. 즉, N=3이면 a, b, c까지의 3개 알파벳으로 출력을 해야 한다. 랑골리의 가운데는 항상 첫번째 문자인 a가 들어가고 그 다음은 알파벳 순서대로 출력이 된다.
문제풀이
def print_rangoli(size):
# your code goes here
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in range(size-1,-size,-1):
rangoli = '-'.join(alp[size-1:abs(i):-1]+alp[abs(i):size])
print(rangoli.center(4*size-3,'-'))
if __name__ == '__main__':
n = int(input())
print_rangoli(n)
'Programming > Python' 카테고리의 다른 글
[Python/Tensorflow] Install & Hello World! (0) | 2021.12.24 |
---|---|
[Python/Hackerrank] Strings > Capitalize! (0) | 2021.12.14 |
[Python/Hackerrank] Strings > String Formatting (0) | 2021.12.10 |
[Python/Hackerrank] Strings > Designer Door Mat (0) | 2021.12.10 |
[Python/Hackerrank] Strings > Text Wrap (0) | 2021.12.09 |
- Total
- Today
- Yesterday
- mysql
- 분석탭
- DATABASE
- hackerrank
- SQL Server
- 테슬라
- string
- 리비안
- 해커랭크
- 경구치료제
- tensorflow
- 대원화성
- MS SQL Server
- 에코캡
- 매매일지
- 코로나19
- 동국알앤에스
- HK이노엔
- list
- 넥스트BT
- insert
- 미중무역전쟁
- Tableau
- python3
- Weather Observation Station
- 몰누피라비르
- 넷플릭스
- MSSQL
- TSQL
- python
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |