이론
O/X를 고르고 틀린 문장은 고치시오.(각 2점,총 20점)
1. 변수를 선언할 때 변수의 타입을 명시해야 한다. X
변수의 타입을 명시하지 않아도 된다.
2. Python에서는 변수에 값을 할당하기 전에 먼저 선언만 할 수 있다. X
선언만 할 수 없으며 초기화를 함으로써 선언됩니다.
3. 리스트와 딕셔너리는 둘 다 순서가 있는 자료형이다. X
딕셔너리는 순서가 없다.
4. 리스트의 요소는 변경할 수 없지만 딕셔너리의 값은 변경 가능하다. X
리스트 또한 요소를 변경할 수 았다.
5. else 블록은 필수적으로 사용해야 한다. X
필수적으로 사용하지 않아도 된다.
6. Python에서는 조건문 안에 다른 조건문을 중첩해서 사용할 수 없다. X
조건안에 다른 조건을 중첩해서 사용할 수 있다.
7. for 루프는 주로 반복 횟수가 정해져 있다. O
8. while 루프는 조건이 참이 되면 종료된다. X
조건이 거짓이 되면 종료된다.
9. 함수의 매개변수는 반드시 필요하다. X
반드시 필요한 건 아니다.
10. 함수는 반드시 return 값을 갖는다. X
반드시 갖는건 아니다.
실습
name = input("학생의 이름을 입력하세요: ")
score = float(input("학생의 성적을 입력하세요: "))
print(f"학생의 이름: {name}")
print(f"학생의 성적: {score:.2f}")
is_graduated = input("학생이 졸업했는지 여부 (yes/no)를 입력하세요: ").lower() == 'yes'
if is_graduated:
print("졸업생")
else:
print("재학생")
subjects = ["Math", "Science", "History", "English", "Art"]
print("2번째, 3번째, 4번째 과목:", subjects[1:4])
student_info = {
"name": name,
"score": score,
"is_graduated": is_graduated
}
print("학생 정보:", student_info)
print("학생 이름:", student_info["name"])
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(f"학생의 학점: {grade}")
if is_graduated:
print("졸업 후 학점 계산")
else:
print("현재 성적 유지")
for idx, subject in enumerate(subjects, start=1):
print(f"{idx}. {subject}")
while True:
score = float(input())
if score <= 0:
break
if score >= 80:
print(f"{score:.2f}점: 합격")
def print_student_score(name, score):
print(f"학생 이름: {name}, 성적: {score:.2f}")
print_student_score(name, score)
def get_max_min_scores(scores):
max_score = max(scores)
min_score = min(scores)
return max_score, min_score
scores = [85, 92, 78, 88, 94]
max_score, min_score = get_max_min_scores(scores)
print(f"최고 성적: {max_score}, 최저 성적: {min_score}")