Skip to content

Instantly share code, notes, and snippets.

@arikchakma
Created December 5, 2022 22:03
Show Gist options
  • Save arikchakma/98b147a15801e0d8e9c4777e44746ba1 to your computer and use it in GitHub Desktop.
Save arikchakma/98b147a15801e0d8e9c4777e44746ba1 to your computer and use it in GitHub Desktop.

Revisions

  1. arikchakma created this gist Dec 5, 2022.
    43 changes: 43 additions & 0 deletions cgpa.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    def gpa(*subs_nums):
    totalGpa = 0
    for num in subs_nums:
    if num >= 90 and num <= 100:
    totalGpa += 4
    elif num >= 85 and num <= 89:
    totalGpa += 3.70
    elif num >= 80 and num <= 84:
    totalGpa += 3.30
    elif num >= 75 and num <= 79:
    totalGpa += 3.00
    elif num >= 70 and num <= 74:
    totalGpa += 2.70
    elif num >= 65 and num <= 69:
    totalGpa += 2.30
    elif num >= 60 and num <= 64:
    totalGpa += 2.00
    elif num >= 55 and num <= 59:
    totalGpa += 1.70
    elif num >= 50 and num <= 54:
    totalGpa += 1.30
    elif num >= 45 and num <= 49:
    totalGpa += 1.00
    else:
    totalGpa += 0
    return totalGpa / len(subs_nums)


    def cgpa():
    totalCgpa = 0
    semestersCompleted = int(input("How many semesters have you completed? "))
    for i in range(semestersCompleted):
    subjects = int(input("How many subjects did you take in semester " + str(i + 1) + "? "))
    print("Enter your marks for semester " + str(i + 1) + ": ")
    marks = []
    for j in range(subjects):
    marks.append(int(input("Enter your mark for subject " + str(j + 1) + ": ")))
    totalCgpa += gpa(*marks)

    return totalCgpa / semestersCompleted


    print("Your CGPA is: " + str(cgpa()))