Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 코드잇
- 포인터
- 깊은복사
- OOP
- 인프런
- 주피터
- 11382번
- 다형성
- list comprehension
- STL
- c++코딩테스트합격자되기
- python
- 코딩테스트
- 얕은복사
- 백준
- 프로그래머스lv2
- 기본클래스
- OpenCV
- 연산자오버로딩
- C++
- 상속
- 멤버함수로구현
- 점프투파이썬
- 동적바인딩
- 유도클래스
- 제네릭프로그래밍
- 데이터사이언스
- 스택
- 람다식
- 참조자
Archives
- Today
- Total
WjExplor Story
[점프 투 파이썬] 3장 제어문 되새김 문제 Q1 ~ Q6 본문
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. 3의 배수의 합 구하기
while 문을 사용하여 1부터 1000까지의 자연수 중 3의 배수의 합을 구하라.
result =0
i=1
while i<=1000:
if i%3==0:
result += i
i+=1
print(result) # 결과값 166833 출력
Q3. 별 표시하기
i =0
while True:
i+=1
if i>5: break
print(i*'*')
*
**
***
****
*****
Q4. 1부터 100 까지 출력하기
for i in range(1,101):
print(i)
i+=1
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 /len(a)
print(average)
Q6. 리스트 컴프리헨션 사용하기
리스트의 요소 중에서 홀수만 골라 2를 곱한 값을 result 리스트에 담는 예시이다.
numbers = [1,2,3,4,5]
result = []
for n in numbers:
if n%2==1:
result.append(n*2)
print(result)
numbers = [1,2,3,4,5]
result = [n*2 for n in numbers if n%2==1]
print(result)
https://youtu.be/Sg33k9IVRr8?si=sMEfKkj6PwBWdMQ0
'Python > Python : Code Study' 카테고리의 다른 글
| 리스트 컴프리헨션(List Comprehension) (0) | 2025.09.11 |
|---|---|
| lambda 식 표현 (0) | 2025.09.11 |
| [점프 투 파이썬] 2장 자료형 되새김 문제 Q8 ~ Q12 (0) | 2025.09.10 |
| Mutable 과 Immutable (1) | 2025.08.31 |
| [점프 투 파이썬] 되새김 문제 Q1 ~ Q7 (1) | 2025.08.31 |