์ ๋๊ฐ๋ vsc์์ ๊ทธ๋ฅ print()๋ก ์ฐ์ด๋ณด๋ฉด ๋๊ฐ๊ฒ ๋์จ๋ค. ๊ทธ๋์ ์ฃผํผํฐ๋ก ํด๋ด ํ์์ ์ฅ์ ์ ์ ๋ ๊ฒ ์์ผ๋ก์ ์ ๋ฆฌ์คํธ ๋ฉ์ด๋ฆฌ๋ฅผ ๋ฌธ์์ด ํ๋๋ก ๋ณผ ์ ์์. ๋ฌธ์ ๊ฐ์์ธ๊ธฐ ๋ฌธ์ ์์ ํ์ฉ ๊ฐ๋ฅ #1~10000์์ ์ซ์ 8์ด ๋ฑ์ฅํ๋ ๊ฐ์ ์ธ๊ธฐ(8808์ +3๊ฐ) # ๋ฐฉ๋ฒ1 print(str(list(range(1, 10001))).count('8')) # ๋ฐฉ๋ฒ2 count = 0 for i in range(1, 10001): if '8' in str(i): count += str(i).count('8') print(count) # ๋ฐฉ๋ฒ3 print(str([i for i in range(1, 10001)]).count('8'))
Global Variable ์ฌ์ฉํ๊ธฐ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ๋ฅผ ํ๋ค๊ฐ ๋ฐ๊ฒฌํ.. function์์์ global variable์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋๋ ์ธ ์๊ฐ๋ ๋ชปํ๋๊ฑฐ๋ผ ํ๋ฒ ์ ๋ฆฌํด๋๊ณ ๋์ด๊ฐ๋ฉด ๋ค์์ ์ฐ๊ฒ ์ง ์ถ์ด์ ์ ๋ฆฌํด๋ณธ๋ค.์ ์ญ๋ณ์๊ฐ ๋ฌด์์ธ์ง ์ด๋ป๊ฒ ์ฐ๋์ง๋ ์ ์๋ ์ฝ๋์ w3schools์ ๊ธ์ ์ฐธ๊ณ ํ๋ฉด ๋๋๊น๋ฐ๋ก ์ ๋ฆฌํ์ง ์์๊ฑฐ๊ณ ์ด๋ป๊ฒ ๋ฌธ์ ์์ ์ผ๋์ง๋ง ๊ฐ๋ตํ ๊ธฐ๋กํด๋ณผ๋ ค๊ณ ํ๋ค.def turn_left(): global direction direction -= 1 if direction == -1: direction = 3๋ฐฉํฅ์ค์ ->์ด๋ ๋ฌธ์ ์ ํ์์ ๋ฐฉํฅ์ ํ ๊ธฐ๋ฅ ๊ตฌํ์ ์ํด ํจ์๋ฅผ ๋ง๋ฆ๋ฐฉํฅ์ ๋ฐ๋ฅธ ์ด๋๋์ dx, dy๋ผ๋ ๋ ๊ฐ์ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ค์ด์ ๊ด๋ฆฌํจ๊ฐ direction์..
Q3: Insect CombinatoricsConsider an insect in an M by N grid. The insect starts at the bottom left corner, (1, 1), and wants to end up at the top right corner, (M, N). The insect is only capable of moving right or up. Write a function paths that takes a grid length and width and returns the number of different paths the insect can take from the start to the goal. (There is a closed-form solution..