SlideShare a Scribd company logo
Understanding For Loop
2017.04.13 - 손건
Today’s Goal
1. 코드를 직접 짜보자
2. For, list를 직접 써보자
3. 피보나치 수열을 짜보자
4. 에라토스 테네스의 체를 짜보자
피보나치가 뭔가요?
피보나치가 뭔가요?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 …
How to do?
1. 맨 처음 결과를 담아줄 list를 한 개 만들어 주자
2. 만들어준 list에 0, 1 을 넣어주자 (정의에 따라서)
3. n번째 원소까지 구해주자
How to do?
Let’s Using ‘for’
1. 어떤게 반복 되는가?
2. 어떤게 바뀌는가?
3. 바뀌는 데이터들의 규칙성?
Let’s Using ‘for’
>>> fib_list.append(fib_list[0] + fib_list[1])
>>> fib_list.append(fib_list[1] + fib_list[2])
>>> fib_list.append(fib_list[2] + fib_list[3])
Let’s Using ‘for’
>>> fib_list.append(fib_list[0] + fib_list[1])
>>> fib_list.append(fib_list[1] + fib_list[2])
>>> fib_list.append(fib_list[2] + fib_list[3])
Let’s Using ‘for’
>>> fib_list.append(fib_list[0] + fib_list[1])
>>> fib_list.append(fib_list[1] + fib_list[2])
>>> fib_list.append(fib_list[2] + fib_list[3])
>>> fib_list.append(fib_list[3] + fib_list[4])
Let’s Using ‘for’
a를 리스트로 바꾸면?
반복되는 부분을 변수 n으로 바꾸면?
arr[n] = arr[n-1] + arr[n-2]
Just Do It!
에라토스테네스의 체
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
: n의 배수들을 삭제하는 방법
삭제 대신 숫자를 0으로 바꿔주자
에라토스테네스의 체
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
1 is not Prime
0
에라토스테네스의 체
0 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
에라토스테네스의 체
0 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
0 2 3 0 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
에라토스테네스의 체
0 2 3 0 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
0 2 3 0 5 0 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
에라토스테네스의 체
0 2 3 0 5 0 7 0 9 0
11 0 13 0 15 0 17 0 19 0
21 0 23 0 25 0 27 0 29 0
31 0 33 0 35 0 37 0 39 0
41 0 43 0 45 0 47 0 49 0
2의 배수를 모두 삭제
에라토스테네스의 체
0 2 3 0 5 0 7 0 9 0
11 0 13 0 15 0 17 0 19 0
21 0 23 0 25 0 27 0 29 0
31 0 33 0 35 0 37 0 39 0
41 0 43 0 45 0 47 0 49 0
0 2 3 0 5 0 7 0 0 0
11 0 13 0 15 0 17 0 19 0
21 0 23 0 25 0 27 0 29 0
31 0 33 0 35 0 37 0 39 0
41 0 43 0 45 0 47 0 49 0
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 15 0 17 0 19 0
0 0 23 0 25 0 0 0 29 0
31 0 0 0 35 0 37 0 0 0
41 0 43 0 0 0 47 0 49 0
3의 배수를 모두 삭제
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 15 0 17 0 19 0
0 0 23 0 25 0 0 0 29 0
31 0 0 0 35 0 37 0 0 0
41 0 43 0 0 0 47 0 49 0
5의 배수를 모두 삭제
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 0 0 17 0 19 0
0 0 23 0 0 0 0 0 29 0
31 0 0 0 0 0 37 0 0 0
41 0 43 0 0 0 47 0 49 0
5의 배수를 모두 삭제
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 0 0 17 0 19 0
0 0 23 0 0 0 0 0 29 0
31 0 0 0 0 0 37 0 0 0
41 0 43 0 0 0 47 0 49 0
이런식으로 0이 아닌 수들(2, 3, 5 ..)의 배수들을 삭제해 나간다
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 0 0 17 0 19 0
0 0 23 0 0 0 0 0 29 0
31 0 0 0 0 0 37 0 0 0
41 0 43 0 0 0 47 0 0 0
이런식으로 0이 아닌 수들(2, 3, 5 ..)의 배수들을 삭제해 나간다
에라토스테네스의 체
0 2 3 0 5 0 7 0 0 0
11 0 13 0 0 0 17 0 19 0
0 0 23 0 0 0 0 0 29 0
31 0 0 0 0 0 37 0 0 0
41 0 43 0 0 0 47 0 0 0
50 미만의 소수들을 다 찾았다!
알아야할 문법들
알아야할 문법들
알아야할 문법들
알아야할 문법들

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Understanding for loop

  • 2. Today’s Goal 1. 코드를 직접 짜보자 2. For, list를 직접 써보자 3. 피보나치 수열을 짜보자 4. 에라토스 테네스의 체를 짜보자
  • 4. 피보나치가 뭔가요? 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 …
  • 5. How to do? 1. 맨 처음 결과를 담아줄 list를 한 개 만들어 주자 2. 만들어준 list에 0, 1 을 넣어주자 (정의에 따라서) 3. n번째 원소까지 구해주자
  • 7. Let’s Using ‘for’ 1. 어떤게 반복 되는가? 2. 어떤게 바뀌는가? 3. 바뀌는 데이터들의 규칙성?
  • 8. Let’s Using ‘for’ >>> fib_list.append(fib_list[0] + fib_list[1]) >>> fib_list.append(fib_list[1] + fib_list[2]) >>> fib_list.append(fib_list[2] + fib_list[3])
  • 9. Let’s Using ‘for’ >>> fib_list.append(fib_list[0] + fib_list[1]) >>> fib_list.append(fib_list[1] + fib_list[2]) >>> fib_list.append(fib_list[2] + fib_list[3])
  • 10. Let’s Using ‘for’ >>> fib_list.append(fib_list[0] + fib_list[1]) >>> fib_list.append(fib_list[1] + fib_list[2]) >>> fib_list.append(fib_list[2] + fib_list[3]) >>> fib_list.append(fib_list[3] + fib_list[4])
  • 11. Let’s Using ‘for’ a를 리스트로 바꾸면? 반복되는 부분을 변수 n으로 바꾸면? arr[n] = arr[n-1] + arr[n-2]
  • 13. 에라토스테네스의 체 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 : n의 배수들을 삭제하는 방법 삭제 대신 숫자를 0으로 바꿔주자
  • 14. 에라토스테네스의 체 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 1 is not Prime 0
  • 15. 에라토스테네스의 체 0 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
  • 16. 에라토스테네스의 체 0 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 0 2 3 0 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
  • 17. 에라토스테네스의 체 0 2 3 0 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 0 2 3 0 5 0 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
  • 18. 에라토스테네스의 체 0 2 3 0 5 0 7 0 9 0 11 0 13 0 15 0 17 0 19 0 21 0 23 0 25 0 27 0 29 0 31 0 33 0 35 0 37 0 39 0 41 0 43 0 45 0 47 0 49 0 2의 배수를 모두 삭제
  • 19. 에라토스테네스의 체 0 2 3 0 5 0 7 0 9 0 11 0 13 0 15 0 17 0 19 0 21 0 23 0 25 0 27 0 29 0 31 0 33 0 35 0 37 0 39 0 41 0 43 0 45 0 47 0 49 0 0 2 3 0 5 0 7 0 0 0 11 0 13 0 15 0 17 0 19 0 21 0 23 0 25 0 27 0 29 0 31 0 33 0 35 0 37 0 39 0 41 0 43 0 45 0 47 0 49 0
  • 20. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 15 0 17 0 19 0 0 0 23 0 25 0 0 0 29 0 31 0 0 0 35 0 37 0 0 0 41 0 43 0 0 0 47 0 49 0 3의 배수를 모두 삭제
  • 21. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 15 0 17 0 19 0 0 0 23 0 25 0 0 0 29 0 31 0 0 0 35 0 37 0 0 0 41 0 43 0 0 0 47 0 49 0 5의 배수를 모두 삭제
  • 22. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 49 0 5의 배수를 모두 삭제
  • 23. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 49 0 이런식으로 0이 아닌 수들(2, 3, 5 ..)의 배수들을 삭제해 나간다
  • 24. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 이런식으로 0이 아닌 수들(2, 3, 5 ..)의 배수들을 삭제해 나간다
  • 25. 에라토스테네스의 체 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 50 미만의 소수들을 다 찾았다!