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 remaining until midnight i.e., 00:00:00 HRS. For each line in the file the function calculates the number of seconds remaining until midnight and appends each into a list. The function then returns that list.

def time_to_midnight(): #time to midnight function
file_name = input("Enter file name: ") #taking file
name
fp1 = open(file_name, 'r') #opening file in read
mode
l=[] #list to store remaining seconds
for line in fp1: #iterating through each line in
file
time, form = line.split(' ')
#splitting every line to time and format based on space
a =[] #list to store time
for i in time.split(':'): #splitts
time into hours, min, sec
a.append(int(i))
form= form.strip() #removing spaces
from format
if (form == "HRS" or form == "AM"):
#if the format is HRS or AM then subtract 24-hours and * 3600
a[0] =
(24-a[0])*3600
elif (form == 'PM'): #if the format
is PM then subtract from 12
a[0] =
(12-a[0])*3600
a[1] = (a[1])*60 #minutes to
seconds
total = (a[0]-a[1])-a[2] #total
seconds remaining
l.append(total) #adding time to
list
print(l) #printing list
time_to_midnight()
contents in file


ex:
20:15:32 HRS
24 - 20 = 4* 3600 = 14,400 #remaining time to reach midnight
15*60 = 900 #minutes
32 #seconds
sec = 14,400 - 900 = 13,500 - 32 = 13,468.
remaining hours to reach midnight converted to seconds and then the finished minutes and seconds are removed from remaining hours.
Write the python function time to midnight() that takes the name of a file containing multiple...
Python: Write a function named "filter_rows" that takes a string as a parameter representing the name of a CSV file with 5 columns in the format "<string>,<int>,<int>,<int>,<int>" and writes a file named "invite.csv" containing the rows from the input file where the value in the fifth column is greater than 101
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 code:
Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...
write a function: Names(path): that reads from a file at location path and returns a dictionary mapping from column names to lists containing the data in those columns. The format of the file is a csv file. The first line is a comma separated set of string names for the columns contained in the file. The function will accumulate a dictionary mapping from year to the list of years, from name to the list of names (in the same order),...
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}
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 Program
5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...
Can someone please write the following program in Python please! 1) Define a function "converT()" that can take a file name, reads line by line to convert temperatures, and returns line by line. Each line in a file begins with a temperature in number {integer or floating point}, followed by one of the temperature unit {"F", "f", "C", "c"}. If "F" or "f", convert the temperature to Celsius. If "C" or "c", convert the temperature to Fahrenheit. The format of...
(Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...
average_value_in_file / Python 3.x: Your assistance is appreciated, thank you! Write a function named average_value_in_file that accepts a file name as a parameter and reads that file, assumed to be full of numbers, and returns the average (mean) of the numbers in that file. The parameter, filename, gives the name of a file that contains a list of numbers, one per line. You may assume that the file exists and follows the proper format. For example, if a file named...