Coding/Code in the Morning

211206_Code in the morning

๊น€์œ ๋‹ˆ์ฝ˜ 2021. 12. 7. 09:39

Code in the morning, ๋งค์ผ ์•„์นจ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’‰๋‹ˆ๋‹ค. 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

x๋งŒํผ ๊ฐ„๊ฒฉ์ด ์žˆ๋Š” n๊ฐœ์˜ ์ˆซ์ž
ํ•จ์ˆ˜ solution์€ ์ •์ˆ˜ x์™€ ์ž์—ฐ์ˆ˜ n์„ ์ž…๋ ฅ ๋ฐ›์•„, x๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด x์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆซ์ž๋ฅผ n๊ฐœ ์ง€๋‹ˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฆฌํ„ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์ œํ•œ ์กฐ๊ฑด์„ ๋ณด๊ณ , ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

 

๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ

  • x๋Š” -10000000 ์ด์ƒ, 10000000 ์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.
  • n์€ 1000 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ๋‚˜์˜ ํ’€์ด 

def solution(x, n):
    answer = []
    for i in range (1, n+1):
        a = i * x
        answer.append(a)
    return answer

* ๋ƒˆ๋˜ ์˜ค๋ฅ˜: list index out of range

list index out of range 

๐Ÿ’ก ๋‹ค๋ฅธ ํ•ด์„ค

pass

 

๐Ÿ‘‰๐Ÿป ๋ฌธ์ œ ๋ฐ”๋กœ๊ฐ€๊ธฐ 

https://programmers.co.kr/learn/courses/30/lessons/12954#qna

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - x๋งŒํผ ๊ฐ„๊ฒฉ์ด ์žˆ๋Š” n๊ฐœ์˜ ์ˆซ์ž

ํ•จ์ˆ˜ solution์€ ์ •์ˆ˜ x์™€ ์ž์—ฐ์ˆ˜ n์„ ์ž…๋ ฅ ๋ฐ›์•„, x๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด x์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆซ์ž๋ฅผ n๊ฐœ ์ง€๋‹ˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฆฌํ„ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์ œํ•œ ์กฐ๊ฑด์„ ๋ณด๊ณ , ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

programmers.co.kr

 

 


 

'Coding > Code in the Morning' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

211224_Code in the morning  (0) 2021.12.24
211222_Code in the morning  (0) 2021.12.23
211206_Code at Night โญ๏ธ  (0) 2021.12.06
211129_Code in the morning  (0) 2021.11.29
211126_Code in the morning  (0) 2021.11.26