Home > Mobile >  I am coding to find average marks & grades with python. However, the process didn't work as I e
I am coding to find average marks & grades with python. However, the process didn't work as I e

Time:03-30

    marks = input("Tell me what marks you got? ")
    marks = list(marks.split(","))

#This split is to remove comma while users input comma

    def find_average_marks(marks):
        sum_of_marks = sum(marks)
        total_subjects = len(marks)
        average_marks = sum_of_marks/total_subjects
        return average_marks

    print(marks)
    average_marks = find_average_marks(marks)
    print("Your average mark is: ", average_marks)

#I also want to know how to work with def too.

it didn't come out as I expected cuz there are some errors. I hope this solve with the help of ur guys.

CodePudding user response:

marks = [ int(x) for x in marks ]

Add this line below marks = list(...)

The mistake you had in your code was that you did not convert your input into numbers and then you got an error when you tried to sum up strings :)

  • Related