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);//changed
if(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 average
result = prompt("Please enter a number, enter -1 to exit");result =parseInt(result);//changed
}document.write("average = " + average);
}
Related Topics
I Want to Reshape 2D Array into 3D Array
How to Import a File in Python With Spaces in the Name
Finding the Max Value in a Two Dimensional Array
How to Write List Elements into a Tab-Separated File
Making a Matrix in Python 3 Without Numpy Using Inputs
Making a Dictionary from Each Line in a File
How to Read a Specific Line from a Text File in Python
Delete Every Non Utf-8 Symbols from String
Check If a Key Exists in a Bucket in S3 Using Boto3
Python How to Use Excelwriter to Write into an Existing Worksheet
How to Count the Amount of Sentences in a Paragraph in Python
Using Selenium in Python to Save a Webpage on Firefox
Update Json Element in Json Object Using Python
Using SQL Server Stored Procedures from Python (Pyodbc)
How to Update a Pyspark Dataframe With New Values from Another Dataframe