Last active
November 15, 2024 03:14
-
-
Save timcsy/6106cc89306f5291fa97de595bfb9ed6 to your computer and use it in GitHub Desktop.
練習:把以下程式用函式重寫
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 學生成績 | |
student1_name = "Alice" | |
student1_score = 85 | |
if student1_score >= 90: | |
student1_grade = "A" | |
elif student1_score >= 80: | |
student1_grade = "B" | |
elif student1_score >= 70: | |
student1_grade = "C" | |
elif student1_score >= 60: | |
student1_grade = "D" | |
else: | |
student1_grade = "F" | |
student2_name = "Bob" | |
student2_score = 72 | |
if student2_score >= 90: | |
student2_grade = "A" | |
elif student2_score >= 80: | |
student2_grade = "B" | |
elif student2_score >= 70: | |
student2_grade = "C" | |
elif student2_score >= 60: | |
student2_grade = "D" | |
else: | |
student2_grade = "F" | |
student3_name = "Charlie" | |
student3_score = 67 | |
if student3_score >= 90: | |
student3_grade = "A" | |
elif student3_score >= 80: | |
student3_grade = "B" | |
elif student3_score >= 70: | |
student3_grade = "C" | |
elif student3_score >= 60: | |
student3_grade = "D" | |
else: | |
student3_grade = "F" | |
student4_name = "Diana" | |
student4_score = 93 | |
if student4_score >= 90: | |
student4_grade = "A" | |
elif student4_score >= 80: | |
student4_grade = "B" | |
elif student4_score >= 70: | |
student4_grade = "C" | |
elif student4_score >= 60: | |
student4_grade = "D" | |
else: | |
student4_grade = "F" | |
# 輸出結果 | |
print("姓名:" + student1_name + ',等第:' + student1_grade) | |
print("姓名:" + student2_name + ',等第:' + student2_grade) | |
print("姓名:" + student3_name + ',等第:' + student3_grade) | |
print("姓名:" + student4_name + ',等第:' + student4_grade) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment