Question

5. Write a Python function called readlinesmton that accepts the name of the file (i.e. filename), starting line number i.e.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 def readlinesmton(filename, m, n):  file = open(filename,"r")       count = 0       content = file.read()   lines = content.split('\n')     for i in lines:                 if i:                   count = count + 1       if m<1:              start=0         else:           start=m-1       if n>count:          end=count       else:           end=n   for line in range(start, end):          print(lines[line]) if __name__ == '__main__':   readlinesmton('data.txt',2,5)

def readlinesmton (filename, m, n): file = open(filename, r) count = 0 content = file.read() lines = content.split(\n), f

Add a comment
Know the answer?
Add Answer to:
5. Write a Python function called readlinesmton that accepts the name of the file (i.e. filename),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python Write the function getSpamLines(filename) that read the filename text file and look for lines of the form &#...

    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...

  • In Python: LoadFile is a function that takes in a string (a filename) and then returns...

    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"]

  • Write a Python function makeDict() that takes a filename as a parameter. The file contains DNA...

    Write a Python function makeDict() that takes a filename as a parameter. The file contains DNA sequences in Fasta format, for example: >human ATACA >mouse AAAAAACT The function returns a dictionary of key:value pairs, where the key is the taxon name and the valus is the total number of 'A' and 'T' occurrences. For example, for if the file contains the data from the example above the function should return: {'human':4,'mouse':7}

  • python 3.7 write a function called read_file() which accepts a filename and returns a list of...

    python 3.7 write a function called read_file() which accepts a filename and returns a list of tuple objects. For example, if we have the following data: 0.000000000 192.168.0.24 10.0.0.5 H-NM 1.001451000 192.168.0.24 10.0.0.5 2.002970000 192.168.0.24 10.0.0.5 3.003552000 192.168.0.24 10.0.0.5 4.005007000 192.168.0.24 10.0.0.5 then the list should contain the following: [('192.168.0.24', 0, 84), ('192.168.0.24', 1, 84), ('192.168.0.24', 2, 84), ('192.168.0.24', 3, 84), ('192.168.0.24', 4, 84)] Note: • Each line consists of a number of fields separated by a single tab character....

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • python program please Write a function called backwards which takes two parameters. The first is a...

    python program please Write a function called backwards which takes two parameters. The first is a file object that has already been opened in read mode called essayfile. The second is called filename, which contains the filename for the output file that will need to be properly opened and closed in your function. The function should read from already opened file object line by line. Each line in the file should have the words on the line reversed. For example,...

  • in python Complete the function read_r_line(fname, ln) to take a filename and a line number and...

    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'

  • In python def lambda_1(filename): # Complete this function to read grades from `filename` and find the...

    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')...

  • java Write a program called Copy that accepts the names of an input file and an...

    java Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt

  • Write the python function time to midnight() that takes the name of a file containing multiple...

    Write the python function time to midnight() that takes the name of a file containing multiple lines of text giving time in HH:MM:SS HRS or HH:MM:SS AM or HH:MM:SS PM format one per line. The HRS notation indicates CSE 101 – Summer 2019 Lab Assignment #9 2 that the time has been given in 24-hour time format. Each line tells the current time of the day. The function reads the file line by line and calculates the number of seconds...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT