#기본형: for 변수 in 시퀀스:
# <반복할 명령>
#시퀀스의 길이만큼 반복된다
for i in [1, 2, 3]:
print('*')
for i in 'abcde':
print(i)
sum = 0
for i in [3, 6, 9]:
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 = total + i
print(total)
print('----range----')
#range(a, b) : a에서 b미만의 자연수 시퀀스를 만들어 준다
#숫자가 중요
for i in range(5,10):
print(i)
#횟수가 중요
for i in range(5):
print(i)
total = 0
for i in range(1, 11):
total = total + i
print(total)
print('----문제----')
#출력 결과가 아래와 같도록 빈칸 넣기
for i in range(1,6):
print('*' * i)
print('----튜플----')
#튜플 () : 여러 개의 값을 하나로 묶어서 저장하는 자료형
#한 번 만들면 절대로 바꿀 수 없다!!
color = ('red', 'yellow', 'blue', 1, 2, [7, 8])
print(color[5][0])
print((3,) * 5) #튜플은 원소가 하나여도 쉼표 필수!
To embed this project on your website, copy the following code and paste it into your website's HTML: