Hey everyone,
I’m currently working on a CGPA calculator app as a small project. I wrote some basic Python code to calculate the CGPA from a list of semester GPAs. The logic seems fine to me, but I’m running into a weird issue when trying to run it.
Here’s the code I wrote:
def calculate_cgpa(gpas):
total = sum(gpas)
count = len(gpas)
cgpa = total / count
return round(cgpa, 2)
gpas_input = input("Enter your semester GPAs separated by spaces: ")
gpas = list(map(float, gpas_input.split()))
cgpa = calculate_cgpa(gpas)
print("Your CGPA is:", cgpa)
I thought this would work smoothly, but it’s not behaving as expected. I want the calculator like this one. Not sure what’s wrong — maybe I’m overlooking something small. If anyone can help me figure it out, I’d appreciate it!
Thanks in advance