๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT๐Ÿ’ก/Python

[Python] ํŒŒ์ด์ฌ ๋ณ„ ์ฐ๊ธฐ - 10๊ฐ€์ง€ ๋ชจ์–‘(์ง๊ฐ์‚ผ๊ฐํ˜•, ํ”ผ๋ผ๋ฏธ๋“œ, ๋งˆ๋ฆ„๋ชจ..)

by hk713 2022. 3. 16.

ํŒŒ์ด์ฌ์„ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋‹ค๋ณด๋ฉด ์ˆœ์กฐ๋กญ๊ฒŒ ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ for๋ฌธ์„ ๋ฐฐ์šฐ๋ฉด์„œ "๋ณ„ ์ฐ๊ธฐ"์— ๋„์ „ํ•˜๊ฒŒ ๋œ๋‹ค.

์—ฌ๊ธฐ์„œ ๋Œ€๋ถ€๋ถ„ ์ฒ˜์Œ  '์ฝ”๋”ฉ์€ ๋‚ด ๊ธธ์ด ์•„๋‹Œ๊ฐ€' ํ•˜๊ณ  ์ƒ๊ฐํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ๋ˆ„๊ตฌ๋‚˜ ์ฒœ์ฒœํžˆ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค๐Ÿ”ฅ

์ •๋ง ์‰ฌ์šด ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์•ฝ๊ฐ„ ๊ณ ๋ฏผํ•ด์•ผ๋˜๋Š” 10๊ฐ€์ง€ ๋ชจ์–‘์˜ ๋ณ„ ์ฐ๊ธฐ๋ฅผ ์ค€๋น„ํ–ˆ๋‹ค.

 

** Python ์ฝ”๋“œ

# 1
for i in range(5):
	print("*")


# 2
print("*" * 5)


# 3
for i in range(5):
	print("*" * 5)


# 4
for i in range(5):
	print((i+1) * "*")


# 5
for i in range(5,0,-1):
    print("*"*i)


#6
for i in range(5):
    for j in range(4-i):
        print(" ",end="")
    for j in range(i+1):
        print("*",end="")
    print()


# 7
for i in range(5):
    for j in range(i):
        print(" ",end="")
    for j in range(5-i):
        print("*",end="")
    print()


# 8
for i in range(5):
    for j in range(4-i):
        print(" ",end="")
    for j in range(2*(i+1)-1):
        print("*",end="")
    print()


# 9
for i in range(5,0,-1):
    for j in range(5-i):
        print(" ",end="")
    for j in range(2*i-1):
        print("*",end="")
    print()


# 10
for i in range(1,10):
    if i <= 5:
        for j in range(5-i):
            print(" ",end="")
        for j in range(2*i-1):
            print("*",end="")
        print()
    else:
        for j in range(i-5):
            print(" ",end="")
        for j in range((10-i)*2-1):
            print("*",end="")
        print()

 

โœ… ์ˆซ์ž๋ฅผ ๊ณ ์ •์‹œํ‚จ์ฑ„๋กœ ์ฝ”๋“œ๋ฅผ ์งฐ๋Š”๋ฐ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ž…๋ ฅ ๋ฐ›์•„ ์ž‘์„ฑํ•˜๋Š” ์ฝ”๋“œ๋กœ ์ˆ˜์ •ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค!

๋Œ“๊ธ€