Python - 문제 미리보기

문제 1826

medium
다음 코드에서 들여쓰기 오류를 수정한 올바른 버전은?
```python
# 오류가 있는 코드:
if 5 > 2:
print("Five is greater than two!")
print("This should be indented too!")
```
A. ```python
if 5 > 2:
print("Five is greater than two!")
print("This should be indented too!")
```
B. ```python
if 5 > 2:
print("Five is greater than two!")
print("This should be indented too!")
```
C. ```python
if 5 > 2:
{print("Five is greater than two!")
print("This should be indented too!")}
```
D. ```python
if 5 > 2:
print("Five is greater than two!")
print("This should be indented too!")
```

정답: B



⦁ 올바른 들여쓰기 규칙:
⦁ 일관된 레벨: 같은 블록 내 모든 코드는 동일한 들여쓰기
⦁ 최소 1칸: 적어도 1칸 이상 들여쓰기 필요
⦁ 권장 4칸: PEP 8 표준에 따른 4칸 공백 사용

⦁ 올바른 코드 (2번):
```python
if 5 > 2:
print("Five is greater than two!") # 4칸 들여쓰기
print("This should be indented too!") # 4칸 들여쓰기
```
⦁ 각 선택지 분석:
⦁ 1번: 들여쓰기 전혀 없음 → SyntaxError
⦁ 3번: 중괄호 사용 → Python에서 지원하지 않음
⦁ 4번: 두 번째 print문 들여쓰기 없음 → if 블록 밖으로 인식

💡 학습 팁

이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.