# for 문 중첩
for i in range(3):
print(i, end="")
print()
for j in range(2):
for i in range(3):
print(i, j, end="")
print()
print()
# 구구단 적용 예
d=2
for a in range(1, 10):
print(d, 'x', a, '=', d * a)
print()
for d in range(2, 10):
for a in range(1, 10):
print(d, 'x', a, '=', d * a)
print()
print()
# 반복문 연습
print('*')
print('**')
print('***')
print()
#
print('*')
print('*', end='')
print()
#
print('*', end='')
print()
print('*', end='')
print('*', end='')
print()
print('*', end='')
print('*', end='')
print('*', end='')
print()
#
for i in range(3):
print('*', end='')
print()
for i in range(2):
print('*', end='')
print()
for i in range(1):
print('*', end='')
print()
#
j=1
for i in range(j):
print('*', end='')
print()
j=2
for i in range(j):
print('*', end='')
print()
j=3
for i in range(j):
print('*', end='')
print()
#
j=0
j=j+1
for i in range(j):
print('*', end='')
print()
j=j+1
for i in range(j):
print('*', end='')
print()
j=j+1
for i in range(j):
print('*', end='')
print()
for j in range(1, 4):
for i in range(j):
print('*', end='')
print()
print()
#
print('***')
print('**')
print('*')
print()
print(' *')
print(' **')
print(' ***')
print(' ****')
print('*****')
print()
# 곱하기 계산
# 2 x 3 = 2 + 2 + 2
a = 2 + 2 + 2
print(a)
# 아래와 같이 바꿀 수 있어야 한다.
# a = a + 1 형태
a = 0
for i in range(3):
a = a + 2
print(a)
print()
# 연습으로 다음을 바꾸어 보자1
a = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
print(a)
a=0
for i in range(10):
a = a + 1
print(a)
# 연습으로 다음을 바꾸어 보자2.
a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
print(a)
a=0
b=0
for i in range(10):
b = b + 1
a = a + b #a=a+1, a=a+2, a=a+3, ... , a=a+10
print(a)
# b=1,2,3,4...
# i=0,1,2,3...
a = 0
for i in range(10):
a = a + (i+1)
print(a)
#
# 2 x 3
s = 0
a = 2
b = 3
for i in range(b):
s = s + a
print(a, 'x', b, '=', s)
# 함수로 바꾸기
def multiply(a=5, b=6):
s = 0
for i in range(b):
s = s + a
print(a, 'x', b, '=', s)
a = 2
b = 3
multiply(2, 3) #함수를 호출한다.
multiply(5, 6)
multiply(3, 4)
# 나눗셈
# 9 / 2
# 9 - 2 - 2 - 2 - 2 > 0; 4번 빼기
# 어렵다.
# while 복습
a = 0
while (a < 3):
print(a)
a=a+1
print()
#
a = 9
b = 2
c = 0 #몫
d = 0 #나머지
s = a
while (s >= b):
s = s - b
c = c + 1
d = s
print(a, '/', b, '=', c, 'x', b, '+', d)
# 함수로 바꾸기
def divide(a, b):
c = 0 #몫
d = 0 #나머지
s = a
while (s >= b):
s = s - b
c = c + 1
d = s
print(a, '/', b, '=', c, 'x', b, '+', d)
divide(9, 2)
댓글 없음:
댓글 쓰기