본문 바로가기

배운다/파이썬

145 : 반복제어문3 - 형성평가6

 

 

풀이 1 )

 

n = int(input("숫자입력: "))

for i in range(n,0,-1):
    for j in range(1,i+1):
        print(" "*(n-i),str(j),end="")
    print()

 

 

 

 

풀이 2 )

 

 

n = int(input())
k = 2 * n - 1 if n < 10 else 17 + 3 * (n - 9)
for i in range(1, n + 1):
    print((' '.join(map(str, range(1, i + 1)))).rjust(k))

 

 

 

풀이 3 )

 

 

number = int(input(''))
pnumber = 1
line = 1
space = number - line
space_ex = 0

while line <= number:
    
    if space_ex == 0:
        print('  '*space, end='')
        space_ex = 1
        space -= 1
    elif pnumber == line:
        print(pnumber)
        line += 1
        pnumber = 1
        space_ex = 0
    else:
        print(pnumber, end=' ')
        pnumber += 1

 

 

 

풀이 4 ) 

 

 

def num_tri(num):
    num_line = ''
    for i in range(1,num+1):
        num_line = num_line + str(i)
        print(num_line.rjust(num))
        
num = int(input())
num_tri(num)