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
- Self-loop attention
- overfitting
- Python
- sigmoid
- pytorch
- python practice
- sentence embedding
- neural net
- machine learning
- NLP
- deep learning
- Transformer
- GNN
- word2vec
- Attention
- abstraction
- elif
- XOR
- Classificaion
- Set Transformer
Archives
- Today
- Total
Research Notes
[Python Practice] While Statement Example - Print Divisible Numbers 본문
Programming Language/Python
[Python Practice] While Statement Example - Print Divisible Numbers
jiachoi 2023. 7. 3. 16:27<Question 1>
# while문을 사용하여 100 이상의 자연수 중 가장 작은 23의 배수를 출력해보세요.
<Answer 1>
i = 100
while i%23 != 0:
i = i+1
print(i)
115
<Explanation 1>
100이상의 자연수중 가장 작은 23의 배수를 찾으려면, 일단 변수 i에 100을 지정해 줘야 한다.
while문에는 i가 23의 배수가 아닌 경우에 True가 수행되어 반복문을 수행하게 해야 한다.
( = i 가 23의 배수일 경우 반복문 종료 후 변수 i 에 23의 배수 저장.)
따라서 이 코드는 while i % 23 != 0:
이렇게 써야하고, 연산자는 %(나머지), !(아니다) 를 사용하였다.
i = i +1 이라는 실행부분을 사용하여 i의 값을 계속 늘린다. i의 값이 23의 배수가 되면 조건문이 False가 되어 조건문을 빠져나온다.
변수 i 에 100이상이지만 가장 작은 23의 배수가 저장되었을 때 출력을 하면 이건 완성

예제 출력 화면
'Programming Language > Python' 카테고리의 다른 글
[Python Practice] While, If Statement - Find factors (0) | 2023.07.03 |
---|---|
[Python Practice] If Statement Example - Grade Calculator (0) | 2023.07.03 |
[Python] Control Statement: While, If/Else/Elif (0) | 2023.07.03 |
[Python Practice] Determine even/odd number (0) | 2023.07.03 |
[Python Practice] Make Change Calculator using Python (0) | 2023.07.03 |