﻿ I Wrote This Code to Take in 5 Grades Take the Average and Display a Message Based on the Average, It Is Acting Up - ITCodar

# I Wrote This Code to Take in 5 Grades Take the Average and Display a Message Based on the Average, It Is Acting Up

## I keep getting this error message for my python program: ValueError: max() arg is an empty sequence

This means that the list `grades` is empty, as you have not appended any values into the list. You can fix it by doing:

``grades = []for student in students:    grade = eval(input(f"Enter the grade for {student}: "))    grades.append(grade)``

Note that this change is at the top part of the code.

## Average calculation

Assuming your data is stored in the database, see SAP's help on AVG

## How to compute the sum and average of elements in an array?

``var sum = 0;for( var i = 0; i < elmt.length; i++ ){    sum += parseInt( elmt[i], 10 ); //don't forget to add the base}var avg = sum/elmt.length;document.write( "The sum of all the elements is: " + sum + " The average is: " + avg );``

Just iterate through the array, since your values are strings, they have to be converted to an integer first. And average is just the sum of values divided by the number of values.

## JavaScript average while loop

Try this..

``var result;var index = 0;var average = 0 ;var sum = 0;result = prompt("Please enter your grade, enter -1 to exit");result =parseInt(result);//changedif(result == -1){alert("no input");}else{while(result != -1){sum = result + sum;         //adds on result to current sumindex++;average = sum / index;      //index divided by sum to get averageresult = prompt("Please enter a number, enter -1 to exit");result =parseInt(result);//changed}document.write("average = " + average);}``

Submit