Coding/Code in the Morning

211024_Code in the Morning

๊น€์œ ๋‹ˆ์ฝ˜ 2021. 10. 24. 12:01

Q1

๋‹ค์Œ ์ฝ”๋“œ์˜ ๊ฒฐ๊ณผ๊ฐ’์€ ๋ฌด์—‡์ผ๊นŒ?

a = "Life is too short, you need python"

if "wife" in a: print("wife")
elif "python" in a and "you" not in a: print("python")
elif "shirt" not in a: print("shirt")
elif "need" in a: print("need")
else: print("none")

A: shirt

 

Q2

while๋ฌธ์„ ์‚ฌ์šฉํ•ด 1๋ถ€ํ„ฐ 1000๊นŒ์ง€์˜ ์ž์—ฐ์ˆ˜ ์ค‘ 3์˜ ๋ฐฐ์ˆ˜์˜ ํ•ฉ์„ ๊ตฌํ•ด ๋ณด์ž.

 

A: 

result = 0
i = 1
while i <= 1000:
    if i%3 == 0:
        result += i
    i += 1
print(result)

Q3

while๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ„(*)์„ ํ‘œ์‹œํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด ๋ณด์ž.

*

**

***

****

*****

i = 0
while True:
    i += 1
    if i > 5 : break
    print("*" * i)

Q4

for๋ฌธ์„ ์‚ฌ์šฉํ•ด 1๋ถ€ํ„ฐ 100๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•ด ๋ณด์ž.

 

A: 

for i in range(1, 101):
    print(i)

 

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

211101_Code in the morning  (0) 2021.11.01
211029_Code in the morning  (0) 2021.10.29
211027_Code in the morning  (0) 2021.10.27
211026_Code in the morning  (0) 2021.10.26
211023_Code in the Morning  (0) 2021.10.23