May-25-2020, 02:14 PM
The error i am getting is
UnboundLocalError: local variable 'marks' referenced before assignment
UnboundLocalError: local variable 'marks' referenced before assignment
def main(): totalMarks = 0 nSubjects = 0 while True: marks == input("Enter for subject " + str(nSubjects + 1) + ": ") if marks == '': break marks = float(marks) if marks < 0 or marks > 100: print("INVALID MARKS !!") continue nSubjects = nSubjects + 1 totalMarks += marks percentage = totalMarks / nSubjects print("Total marks: ",int(totalMarks)) print("Number of Subjects: ",nSubjects) print("Percentage: ", round(percentage, 2)) if __name__ == "__main__": main()But if i set the marks to 0 the if statement is not executed
Quote: totalMarks = 0
nSubjects = 0
marks = 0
