본문 바로가기

배운다/파이썬

149 : 반복제어문3 - 형성평가A

풀이 1 )

n = int(input())
x = 1
for i in range(n):
    for j in range(n):
        if x > 10:
            x = 1
        print(x, end="")
        x += 2
    print("")

 

 

풀이 2) 

n = int(input())
j = 0
for _ in range(n):
    for _ in range(n):
        print((2 * j + 1) % 10, end=' ')
        j += 1
    print()

풀이 3 )

number = int(input(''))

pnumber = 1
column = 1
row = 1

while row <= number and column <= number:
    if pnumber > 10:
        pnumber = 1
    if column == number:
        print(pnumber)
        column = 1
        row += 1
        pnumber += 2
    else:
        print(pnumber, end = ' ')
        column += 1
        pnumber += 2

풀이 4 )

def odd_square(num):
    a = 1
    for i in range(0,num):
        src = ""
        for i in range(0,num):
            src += str(a)
            a = a+2
            if a == 11:
                a = 1
            else:
                continue
            
        print(src)
            
num = int(input())
odd_square(num)