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 |