In python
def lambda_1(filename):
# Complete this function to read grades from `filename` and find
the minimum
# student test averages. File has student_name, test1_score,
test2_score,
# test3_score, test4_score, test5_score. This function must use a
lambda
# function and use the min() function to find the student with the
minimum
# test average. The input to the min function should be
# a list of lines. Ex. ['student1,33,34,35,36,45',
'student2,33,34,35,36,75']
# input filename
# output: (lambda_func, line_with_min_student) -- example
(lambda_func, 'student1,33,34,35,36,45')
# YOUR CODE HERE
raise NotImplementedError()
This is an example of the file
student1,94,88,86,78,94
student2,88,78,80,84,80
student3,84,97,85,73,76
student4,72,99,72,86,82
student5,71,92,71,77,91
The following program does the required tasks. Read the comments to understand.
#Lambda function to be implemented
def lambda_1(filename):
f1 = open(filename,"r")
#list of lines
students = f1.readlines()
#A lambda function to calculate average for each line
lambda_func = lambda x : sum(list(map(int,x.split(",")[1:])))/5
#min function using the lambda function to find the minimum value
st = min(students, key=lambda_func)
#The output to be returned
return (lambda_func, st)
print(lambda_1("inp.txt"))
inp.txt:
student1,94,88,86,78,94
student2,88,78,80,84,80
student3,84,97,85,73,76
student4,72,99,72,86,82
student5,71,92,71,77,91
Output:
(<function lambda_1.<locals>.<lambda> at 0x00000254EDD47790>, 'student5,71,92,71,77,91')
The min function returns the minimum element for which the value of lambda(average) is minimum.
In python def lambda_1(filename): # Complete this function to read grades from `filename` and find the...
In Python: LoadFile is a function that takes in a string (a filename) and then returns a list. The list is the contents of the file, where each element is a list of data from the file. Here's an example of using this function. The input file had four lines of text. >>> lines = LoadFile("test.txt") >>> print("OUTPUT", lines) OUTPUT ["Hello there", "I am a test file", "please load me in and print me out", "Thanks"]
(IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...
### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...
Consider the following function: def get_largest(filename): input_file = open(filename, 'r') lines = input_file.readlines() input_file.close() largest = 0 for line in lines: items_list = line.split() for element in items_list: value = float(element) if value > largest: largest = value return largest The function takes a filename as a parameter and returns the largest number in the file as a float. Modify the above function and use a try-except-else block to handle exceptions that may occur and handle the FileNotFoundError in your...
python
Write the function getSpamLines(filename) that read the filename text file and look for lines of the form 'SPAM-Confidence: float number'. When you encounter a line that starts with "SPAM-Confidence:" extract the floating-point number on the line. The function returns the count of the lines where the confidence value is greater than 0.8. For example, if 'spam.txt' contains the following lines along with normal text getSpamLines('spam.txt') returns 2. SPAM-Confidence: 0.8945 Mary had a little lamb. SPAM-Confidence: 0.8275 SPAM-Confidence: 0.7507 The...
Use python
Start:
def main():
gradeList = []
fileName = getFile()
gradeList = getData(fileName)
mean = calculateMean(gradeList)
sd = calculateSD(mean, gradeList)
displayHeadings(gradeList, mean, sd)
curveGrades(mean, sd, gradeList)
if __name__ == "__main__":
main()
For this program, you will create a grade curving program by reading grades from a file, calculating the mean and standard deviation. The mean is the average value of the grades and the standard deviation measures the spread or dispersal of the numbers from the...
python 3
HW11.2. Read a file and print its lines The function takes a single string parameter, which is the name of a file. Complete the function to open the file for reading, read the lines of the file, and print out each line. The function takes a single string parameter, which function to open the file for reading, read the lines student.py def print_lines of file (filename): 1
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
Consider python please for this problem: I did a python program to read the first 20 lines from a file and here is the code holder = 20 lines = 3 file = "123456.pssm" _file = ".txt" while 1: out_file = input("[OUTPUT] - Please enter the name of file: ") + _file if (not _file): print("Filename not specified - Please Try Again\n") continue break with open(_file, "a") as e: with open(file, "r") as f: for num, line in enumerate(f, 1): ...
in python Complete the function read_r_line(fname, ln) to take a filename and a line number and return the contents of that line number from the file as a string. Hint: The code from Files03 will be helpful. Example: read_r_line('myf.txt', 5) will return 'I like peanut'