-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice9.py
More file actions
74 lines (73 loc) · 1.79 KB
/
practice9.py
File metadata and controls
74 lines (73 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 입력한 횟수대로 반복하기
count = int(input('반복할 횟수를 입력하세요: '))
for i in range(count):
print('Hello, world!', i)
# 20부터 10까지 출력하는 방법
for i in range(20, 9, -1):
print(i, end=' ')
print('\n')
for i in reversed(range(10, 21)):
print(i, end=' ')
print('\n')
# 연습문제: 리스트의 요소에 10을 곱해서 출력하기
x = [49, -17, 25, 102, 8, 62, 21]
for i in x:
print(i*10, end=' ')
print('\n')
# 심사문제: 구구단 출력하기
dan = int(input())
for i in range(1, 10):
print(dan, '*', i, '=', dan*i)
# while 반복문으로 Hello, world! 100번 출력하기
# i = 0
# while i < 100:
# print('Hello, world!', i)
# i += 1
# 연습문제: 변수 두 개를 다르게 반복하기
i = 2
j = 5
while i <= 32 or j >= 1:
print(i, j)
i *= 2
j -= 1
# 심사문제: 교통카드 잔액 출력하기
price = int(input())
while price >= 1350:
price -= 1350
print(price)
# for에서 break으로 반복문 끝내기
for i in range(10000):
print(i)
if i == 100:
break
# while에서 break으로 반복문 끝내기
i = 0
while True:
print('Hello, world!', i)
i += 1
if i == 100:
break
# 연습문제: 3으로 끝나는 숫자만 출력하기
# 0과 73 사이의 숫자 중 3으로 끝나는 숫자만 출력되게 만드세요.
i = 0
while True:
# 3으로 끝나지 않는 숫자는 1증가하고 건너뛴다.
if i % 10 != 3:
i += 1
continue
if i > 73:
break
print(i, end=' ')
i += 1
print('\n')
# 심사문제: 두 수 사이의 숫자 중 3으로 끝나지 않는 숫자 출력하기
start, stop = map(int, input().split())
i = start
while True:
if i > stop:
break
if i % 10 == 3:
i += 1
continue
print(i, end=' ')
i += 1