Leta Learns

[Python] Intermediate Low - Basic #단순 반복문 본문

Coding/codetree

[Python] Intermediate Low - Basic #단순 반복문

leta 2021. 8. 3. 16:43

 

#단순 반복문

 

 

- 19단 출력 https://www.codetree.ai/missions/2/concepts/1/problems/nineteen-times-table/description

 

코드트리

삼성 SW역량테스트, 코드트리와 함께

www.codetree.ai

for i in range(1, 20):
    for j in range(1, 20, 2):
        if j == 19:
            print(i,"*",j,"=",i*j)
        else:
            print(i,"*",j,"=",i*j,"/",i,"*",(j+1),"=",i*(j+1))

 

 

 

 

- 별 그리기 https://www.codetree.ai/missions/2/concepts/1/problems/star-drawing/description

 

코드트리

삼성 SW역량테스트, 코드트리와 함께

www.codetree.ai

n = int(input())
for i in range(0, n):
    print(" "*(n-(i+1)),end='')
    print("*"*((2*i)+1))
for i in range(0, n):
    print(" "*(i+1),end='')
    print("*"*((2*n)-(2*i)-3))

 

 

 

 

- 약수의 개수가 3개인 수 https://www.codetree.ai/missions/2/concepts/1/problems/square-of-prime-number/description

 

코드트리

삼성 SW역량테스트, 코드트리와 함께

www.codetree.ai

start, end = map(int, input().split())
candidate = []
count = 0
for i in range(start, end+1):
    for j in range(2, i):
        if i % j == 0:
            candidate.append(i)

for i in candidate:
    if candidate.count(i) == 1:
        count += 1

print(count)

 

 

 

 

- 숫자 뒤집기 https://www.codetree.ai/missions/2/concepts/1/problems/flip-integer/description

 

코드트리

삼성 SW역량테스트, 코드트리와 함께

www.codetree.ai

natural = input()
natural_1 = natural
for i in range(len(natural)):
    if natural[-1] == '0':
        natural = natural.replace(natural[-1], "")
    if natural_1[i] != '0':
        print(natural[len(natural)-i-1],end='')

 

 

 

'Coding > codetree' 카테고리의 다른 글

[Python] Intermediate Low - DP  (0) 2021.08.13
[Python] Intermediate Low - DFS , BFS  (0) 2021.08.11
[Python] Intermediate Low - Basic #최대 최소  (0) 2021.08.03
Comments