## 이론문제 ##
# O/X를 고르고 틀린 문장은 고치시오.(각 2점,총 20점)
# 1. 변수를 선언할 때 변수의 타입을 명시해야 한다. x (=> 명시하지 않아도 된다. 할당된 값에 따라 자동으로 변수의 타입이 결정됨)
# 2. Python에서는 변수에 값을 할당하기 전에 먼저 선언만 할 수 있다. x (=> 변수 선언 전에 할당을 먼저 해야 함)
# 3. 리스트와 딕셔너리는 둘 다 순서가 있는 자료형이다. x (=> 딕셔너리는 순서가 없는 자료형이다.)
# 4. 리스트의 요소는 변경할 수 없지만 딕셔너리의 값은 변경 가능하다. x (=> 리스트 요소도 변경 가능)
# 5. else 블록은 필수적으로 사용해야 한다. x (=> else 블록 없어도 됨)
# 6. Python에서는 조건문 안에 다른 조건문을 중첩해서 사용할 수 없다. x (=> 중첩 조건문 가능)
# 7. for 루프는 주로 반복 횟수가 정해져 있다. o
# 8. while 루프는 조건이 참이 되면 종료된다. x (=> 거짓이 되면 종료)
# 9. 함수의 매개변수는 반드시 필요하다. x (=> 매개변수가 없을 수도 있음)
# 10. 함수는 반드시 return 값을 갖는다. x (=> 반환값이 없을 수도 있음)
## 실습문제 ##
# Q1
name = input("이름을 입력해주세요")
score = float(input("점수를 입력해주세요"))
print(f"학생 이름: {name}, 성적: {score:.2f}")
# Q2
is_graduated = input().lower() == "yes"
if is_graduated:
print("졸업생")
else:
print("재학생")
# Q3
subjects = ["Math", "Science", "History", "English", "Art"]
print("2번째, 3번째, 4번째 과목:", subjects[1], subjects[2], subjects[3])
-> print("2번째, 3번째, 4번째 과목:", subjects[1:4])
# Q4
student_info = {"name": name, "score" : score, "is_graduated" : is_graduated}
print("학생 정보:", student_info)
print("학생 이름:", student_info["name"])
# Q5
if score >= 90 :
grade = "A"
elif score >= 80 :
grade = "B"
elif score >= 70 :
grade = "C"
else :
grade = "F"
print(f"학생의 학점: {grade}")
# Q6
if is_graduated:
print("졸업 후 학점 계산")
else:
print("현재 성적 유지")
# Q7
for idx, subject in enumerate(subjects, start=1) :
print(f"{idx}. {subject}")
# Q8
while True :
score = float(input())
if score <= 0 :
break
if score >= 80 :
print(f"{score:.2f}점: 합격")
# Q9
def print_student_score(name,score):
print(f"학생 이름: {name}, 성적: {score:.2f}")
print_student_score(name,score)
# Q10
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}")