#for문 - 시퀀스의 길이만큼 반복된다
'''
for 변수 in 시퀀스:
    반복할 명령
'''
for i in 'abcd':
    print(i)

for a in [1, 2, 3]:
    print(a)

sum = 0
for i in [3, 6, 9]:
    sum += i #sum = sum + i
    print(sum)

print('----문제1----')
#1부터 10까지 for문을 이용해서 합계total 구하기
total = 0
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    total += i #total = total + i
print(total)

#range(a, b) : a부터 b미만의 연속된 자연수
#숫자(구간)이 중요
for i in range(5, 10):
    print(i)

#반복의 횟수가 중요
for i in range(5): #0부터 4까지
    print('*')

print('----문제2----')
#1부터 10까지 for, range를 이용해서 합계total 구하기
total = 0
for i in range(1, 11):
    total += i #total = total + i
print(total)

print('----문제3----')
for i in range(1, 6):
    print('*' * i)

print('----문제4----')
#100부터 1000까지 for, range를 이용해서 합계total 구하기
total = 0
for i in range(100, 1001):
    total += i #total = total + i
print(total)

#중첩 반복문
for i in range(2, 10):
    for j in range(1, 10):
        print(f'{i} * {j} = {i*j}', end = '\t')
    print()


#for과 while의 차이
i = 1
while i <= 5: #조건이 참일 때 반복
    print(i)
    i += 1

for j in range(1, 6): #정해진 횟수만큼 반복
    print(j)




    

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: