Q5
A ํ๊ธ์ ์ด 10๋ช ์ ํ์์ด ์๋ค. ์ด ํ์๋ค์ ์ค๊ฐ๊ณ ์ฌ ์ ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
[70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
for๋ฌธ์ ์ฌ์ฉํ์ฌ A ํ๊ธ์ ํ๊ท ์ ์๋ฅผ ๊ตฌํด ๋ณด์.
ํ์ด:
๋๋ณด๊ธฐ
A = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
total = 0
for score in A:
total += score
average = total/10
print(average)
Q6
๋ฆฌ์คํธ ์ค์์ ํ์์๋ง 2๋ฅผ ๊ณฑํ์ฌ ์ ์ฅํ๋ ๋ค์ ์ฝ๋๊ฐ ์๋ค.
numbers = [1, 2, 3, 4, 5] result = [] for n in numbers: if n % 2 == 1: result.append(n*2)
์ ์ฝ๋๋ฅผ ๋ฆฌ์คํธ ๋ดํฌ(list comprehension)๋ฅผ ์ฌ์ฉํ์ฌ ํํํด ๋ณด์.
ํ์ด:
๋๋ณด๊ธฐ
numbers = [1, 2, 3, 4, 5]
result = [num * 2 for num in numbers if num%2 ==1]
print(result)
'Coding > Code in the Morning' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
211103_Code in the morning (0) | 2021.11.03 |
---|---|
211101_Code in the morning (0) | 2021.11.01 |
211027_Code in the morning (0) | 2021.10.27 |
211026_Code in the morning (0) | 2021.10.26 |
211024_Code in the Morning (0) | 2021.10.24 |