위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# 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")
''' 결괏값 : shirt
가장 먼저 참이 되는 조건이 세 번째이기 때문
'''
# Q2
result = 0
i = 1
while i <= 1000:
if i % 3 == 0:
result += i
i += 1
print(result)
# Q3
i = 1
while i <= 5:
print('*' * i)
i += 1
# Q4
for i in range(1, 101):
print(i)
# Q5
mid = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
total = 0
for i in mid:
total += i
avg = total / len(mid)
print(avg)
# Q6 : 리스트 내포(list comprehension) 사용하기
numbers = [1, 2, 3, 4, 5]
result = []
for n in numbers:
if n % 2 == 1:
result.append(n*2)
numbers = [1, 2, 3, 4, 5]
result = [n*2 for n in numbers if n%2 ==1]
print(result)
|
'Python & SQL > Python Problems' 카테고리의 다른 글
| [점프 투 파이썬] 05장 연습 문제 풀이 (0) | 2021.04.18 |
|---|---|
| [점프 투 파이썬] 04장 연습 문제 풀이 (0) | 2021.04.18 |
| [점프 투 파이썬] 02장 연습 문제 풀이 (0) | 2021.04.16 |
| [초보 300제] 파이썬 파일 입출력과 예외 처리(291~300) 풀이 (0) | 2021.04.12 |
| [초보 300제] 파이썬 클래스(251~290) 풀이 (0) | 2021.04.12 |