def getSpamLines(filename):#definition of function
filename=open("spam.txt","r")#open file in read mode
list1=[]#declare list1=[],list2=[] and count=0
list2=[]
count=0
for lines in filename:#so for each line in filename split it
for word in lines.split():
list2.append(word)#and append each word to the list2
list1.append(list2)#append list2 to list1
list2=[]#again put list2=[]
#print(list1)
for i in list1:#for each element in list1
for ele in range(len(i)):#for element in i
#print(i[ele])
if (i[ele]=="SPAM-Confidence:"):#if ele is SPAM-Confidence:
if(float(i[ele+1])>0.8):#then it finds the value of SPAM-Confidence:
count=count+1#if it is greater than 0.8 it increments count
return count#it returns number of line which are having SPAM-Confidence:>0.8
print(getSpamLines("spam.txt"))#calling the function
![getspamLines (filename):#definition filename-open (span. txt, r)#open list1-[]#declare list!-[], 11st2-[] list2-[] of fun](http://img.homeworklib.com/images/83d9d4a8-f4ba-4635-8a37-e83599ff310a.png?x-oss-process=image/resize,w_560)

spam.txt

python Write the function getSpamLines(filename) that read the filename text file and look for lines of the form &#...
Write a program in python that reads each line in a file, reverses its lines, and writes them to another file. For example, if the file input.txt contain the lines: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go. and you run your Python file then output.txt contains The lamb was sure to go. And everywhere that Mary went Its fleece was white as snow Mary had...
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...
QUESTION17 The following Python script aims to read lines from a text file and add them to a list Marlout oft. 00 Example P Flag question If the text file contains the following lines wordt wordz words the list will be ['word, word2, Words' after the execution of the program Question: Rearrange the following statements on the correct (logical) form Note: The-indicates the indentation #--> Program infile=onen/fileName --infile = open(fileName, 'r') . . -try: --for line in infile: --infile =...
5. Write a Python function called readlinesmton that accepts the name of the file (i.e. filename), starting line number i.e. m) and ending line number (i.e. n) as a parameter. The function then returns the contents from line number m to n (m <n). If m < 1 then start from line 1. Similarly, if n > number of lines the file, then stop at the last line in the file. Sample Input: readlinesmton("data.txt",5,7) Sample Input: readlinesmton("data.txt", 0,10)
PYTHON: Write a function that takes, as an argument, the name of a file, fileName, and an integer n between -750 and 750 (inclusive). Your program should verify that n is an integer in the correct range. If it is not, it should return the string “Your integer is out of range.” If it is in the correct range, your program should open (and read through) the file specified, and return the number of values in the file that are...
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
Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...
( IN JAVA): Write a program that reads each line in a file, and writes them out in reverse order into another file. This program should ask the user for the name of an input file, and the name of the output file. If the input file contains: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go Then the output file should end up containing: The lamb...
C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything. Your function should be named...
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...