# 用 Python 製作成績轉換器

Fariba Laiq 2022年5月26日

## 用 Python 製作成績轉換器

### 簡單成績轉換器

• ##### 最後，我們將使用 `if-else` 條件為每個平均分數範圍分配一個成績。

``````# Python 3.x
total_marks = 0
print("Enter Marks Obtained in 4 Subjects: ")
for i in range(1, 5):
marks = int(input("Enter the marks for subject:" + str(i) + " "))
total_marks = total_marks + marks
avg_marks = total_marks / 4
if avg_marks >= 91 and avg_marksg <= 100:
elif avg_marks >= 81 and avg_marks < 91:
elif avg_marks >= 71 and avg_marks < 81:
elif avg_marks >= 61 and avg_marks < 71:
elif avg_marks >= 51 and avg_marks < 61:
elif avg_marks >= 41 and avg_marks < 51:
else:
``````

``````#Python 3.x
Enter Marks Obtained in 4 Subjects:
Enter the marks for subject:1 90
Enter the marks for subject:2 80
Enter the marks for subject:3 60
Enter the marks for subject:4 70
``````

### 加權成績轉換器

1. 10%的權重屬於作業的平均分。
2. 20%的權重屬於實驗室任務的平均分。
3. 70%的權重屬於考試的平均分。

``````# Python 3.x
total_marks = 0
exam1 = int(input("Enter Marks Obtained in Exam 1: "))
exam2 = int(input("Enter Marks Obtained in Exam 2: "))
avg_exam = (exam1 + exam2) / 2
totallab = 0
totalassignment = 0
for i in range(1, 3):
marks = int(input("Enter Marks Obtained in Lab Task: " + str(i) + " "))
totallab = totallab + marks
avglab = totallab / 2
for i in range(1, 5):
marks = int(input("Enter the marks for Assignment:" + str(i) + " "))
totalassignment = totalassignment + marks
avgassignment = totalassignment / 4
avg_marks = 0.1 * avgassignment + 0.7 * avg_exam + 0.2 * avglab
if avg_marks >= 91 and avg_marksg <= 100:
elif avg_marks >= 81 and avg_marks < 91:
elif avg_marks >= 71 and avg_marks < 81:
elif avg_marks >= 61 and avg_marks < 71:
elif avg_marks >= 51 and avg_marks < 61:
elif avg_marks >= 41 and avg_marks < 51:
else:
``````

``````#Python 3.x
Enter Marks Obtained in Exam 1: 40
Enter Marks Obtained in Exam 2: 60
Enter Marks Obtained in Lab Task: 1 20
Enter Marks Obtained in Lab Task: 2 40
Enter the marks for Assignment:1 60
Enter the marks for Assignment:2 10
Enter the marks for Assignment:3 30
Enter the marks for Assignment:4 40