Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 참고블로그
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- callback
- JS #프로젝트
- Project
- ajax
- 동기
- db
- Import
- await
- webpack
- promise
- json
- Porject
- database
- 비동기
- execCommand
- mysql
- 게임
- slow and steady
- eport
- setTimeout()
- https://m.blog.naver.com/tt2t2am1118/221010125300
- prj
- sql
- 혼프
- object
- async
- addEventListener
- js
Archives
- Today
- Total
C-log
Welcome to Python : while문 본문
728x90
- if문 : https://hi-code.tistory.com/116
- while문 : https://hi-code.tistory.com/117
- for문 : https://hi-code.tistory.com/118
Title | Code | Console |
while문 | ||
while문 기본 구조 |
treeHit = 0 while treeHit < 10:
treeHit = treeHit + 1
print("나무를 %d번 찍었습니다." % treeHit)
if treeHit == 10:
print("나무 넘어갑니다.")
|
나무를 1번 찍었습니다. 나무를 2번 찍었습니다. 나무를 3번 찍었습니다. 나무를 4번 찍었습니다. 나무를 5번 찍었습니다. 나무를 6번 찍었습니다. 나무를 7번 찍었습니다. 나무를 8번 찍었습니다. 나무를 9번 찍었습니다. 나무를 10번 찍었습니다. 나무 넘어갑니다. |
prompt = """ 1. Add
2. Del
3. List
4. Quit
Enter number :
"""
number = 0
#4를 입력하면 while문을 빠져나간다.
while number != 4:
print(prompt)
number = int(input())
|
1. Add 2. Del 3. List 4. Quit Enter number : |
|
break |
coffee = 10 while True:
money = int(input("돈을 넣어주세요."))
if money == 300:
print("커피를 줍니다.")
coffee = coffee - 1
elif money > 300:
print("거스름돈 %d를 주고 커피를 줍니다." % (money - 300))
coffee = coffee - 1
else:
print("돈을 다시 돌려 주고 커피를 주지 않습니다.")
print("남은 커피의 양은 %d개입니다. " % coffee)
if coffee == 0:
print("커피가 다 떨어졌습니다. 판매를 중지합니다.")
break
|
돈을 넣어주세요.200 돈을 다시 돌려 주고 커피를 주지 않습니다. 남은 커피의 양은 10개입니다. 돈을 넣어주세요.400 거스름돈 100를 주고 커피를 줍니다. 돈을 넣어주세요.300 커피를 줍니다. 돈을 넣어주세요. |
continue |
a = 0 while a < 10:
a = a + 1
if a % 2 == 0:
continue
print(a)
|
1 3 5 7 9 |
무한 루프 |
while True: print("Ctrl+C를 눌러야 while 문을 빠져나갈 수 있습니다.")
|
Ctrl+C를 눌러야 while 문을 빠져나갈 수 있습니다. Ctrl+C를 눌러야 while 문을 빠져나갈 수 있습니다. . . . |
728x90
'📘Python' 카테고리의 다른 글
Welcome to Python : 함수 (0) | 2023.07.13 |
---|---|
Welcome to Python : for문 (0) | 2023.07.09 |
Welcome to Python : if문 (0) | 2023.07.09 |
Welcome to Python : 깊은 복사 얕은 복사 (0) | 2023.07.09 |
Welcome to Python : 집합 자료형 (0) | 2023.07.08 |
Comments