Lambda functions in Python are anonymous functions that are single expression functions to work on variables.
For in loop is used to iterate over an array and return the value at the current index.
Here, we will apply the given lambda function to return the grade of the students of a class. The marks of all students are stored in an array. And we will use the for in loop to access each value of the array.
studentMarks = [56,77,88,45,2,27,44]
studentGrades = lambda:['First' if (per>=60 and per<=100) else
'Second' if(per>=45 and per<=59) else 'Fail'
for per in studentMarks]
print(studentGrades())
In the above code, we are creating an array named studentMarks that will store the marks of students and then using the lambda function, we have calculated the grades of students based on their marks and store it in an array studentGrades. At last, we have printed the array.
Program to illustrate the working of our solution
Output:
Explanation:
In the above code, we are creating an array named studentMarks that will store the marks of students and then using the lambda function, we have calculated the grades of students based on their marks and store it in an array studentGrades. At last, we have printed the array.
need an explanation for this answer? contact us directly to get an explanation for this answer