MapleStory Finger Point

๐Ÿ’Ž Python/๐Ÿ“šํŒŒ์ด์ฌ for Beginner (2ํŒ)

(๊ฐœ๋…) ๋ฐ˜๋ณต๋ฌธ - ํŒŒ์ด์ฌ for Beginner (2ํŒ)

HYEJU01 2024. 3. 19. 22:53

· ๋ฐ˜๋ณต๋ฌธ 

for ๋ฌธ / while ๋ฌธ

 

· for in list

list ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณต

list ๊ฐ’ ๊บผ๋‚ด์˜ด

 

·  for ๋ฌธ

for ๋ณ€์ˆ˜ in range (์‹œ์ž‘๊ฐ’, ๋๊ฐ’+1 , ์ฆ๊ฐ€๊ฐ’) :
	๋ฐ˜๋ณต๋ฌธ
    
  
  
range(3)
range(0,3)
range(0,3,1) ๊ณผ ๊ฐ™์Œ

์‹œ์ž‘๊ฐ’, ์ฆ๊ฐ€๊ฐ’์€ ์ƒ๋žต๊ฐ€๋Šฅ ์ƒ๋žตํ•˜๋ฉด

0 , 1 ๋กœ ๋ฐฐ์น˜

 

ํ‘œ์‹œํ•œ ์ˆซ์ž ๋ณด๋‹ค ํ•˜๋‚˜ ์ ์€ ์ˆซ์ž๊นŒ๋งŒ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ

๋๊ฐ’์„ ์„ค์ •ํ• ๋•Œ +1 ํ•˜๋Š” ๊ฒƒ์„ ์ฃผ์˜ํ•ด์•ผํ•œ๋‹ค

 

·  ๋ณ€์ˆ˜ ์‚ฌ์šฉ ์•ˆํ•˜๋ ค๋ฉด ์–ธ๋”๋ฐ” _ ์‚ฌ์šฉ

for _ in range (์‹œ์ž‘๊ฐ’, ๋๊ฐ’+1, ์ฆ๊ฐ€๊ฐ’):

 

·  end = " "   ๋งˆ์ง€๋ง‰์„ ๊ณต๋ฐฑ์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์„œ ํ•œ์นธ์”ฉ ๋„์–ด ์ถœ๋ ฅ ๊ฐ€๋Šฅ

 

·   ์ค‘์ฒฉ for ๋ฌธ

i,k=0,0

for i in range (0,3,1) :
    for k in range (0,2,1) :
        print("ํŒŒ์ด์ฌ ๊ฟ€์žผ ~ %d %d" %(i,k))

 

·   while ๋ฌธ = ์กฐ๊ฑด์‹์ด ์ฐธ์ผ๋•Œ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐฉ์‹ ์‚ฌ์šฉ

๋ณ€์ˆ˜ = ์‹œ์ž‘๊ฐ’
while ๋ณ€์ˆ˜ < ๋๊ฐ’ : 
	 ์ด ๋ถ€๋ถ„์„ ๋ฐ˜๋ณต
     ๋ณ€์ˆ˜ = ๋ณ€์ˆ˜ + ์ฆ๊ฐ€๊ฐ’

 

· ๋ฌดํ•œ ๋ฃจํ”„ while ๋ฌธ

while (true) :

 

·  break ๋ฌธ

๋ฌด์กฐ๊ฑด ๋ฐ˜๋ณต๋ฌธ์„ ๋น ์ ธ๋‚˜์˜จ๋‹ค.

 

 

·  coutinue ๋ฌธ

๋‚จ์€ ๋ถ€๋ถ„์„ ๋ฌด์กฐ๊ฑด ๊ฑด๋„ˆ ๋›ฐ๊ณ  , ๋ฐ˜๋ณต๋ฌธ ์ฒ˜์Œ์œผ๋กœ ๋Œ์•„๊ฐ„๋‹ค.