Part A:
def word_from_file(file):
file1 = open(file, mode = 'r') # 'r' is to read
text = file1.read()
file1.close()
return text.split()[0].strip()
![In [16]: def word_from_file(file): file1 = open(file, mode = r) # r is to read text = file1.read() file1.close() return t](http://img.homeworklib.com/questions/c59b4660-aa2e-11eb-91c3-29d99e32a2b1.png?x-oss-process=image/resize,w_560)
Part B:
import ast #to remove the quotation marks at the
starting and end of individual list
def nested_int_list_from_file(file):
file1 = open(file, mode = 'r') # 'r' is to read
num_lines = file1.readlines() #to read all the lines at instance
from the file
file1.close()
numbers_list = [] #intializing an empty string
for line in num_lines:
c = ast.literal_eval("["+''.join(line.strip().split())+"]")
numbers_list.append(c) #appending to the empty list
return numbers_list
Task 1: Reading files Part A - Read a word Implement a function word from.file(file) that...
Reading and Writing Complete Files in C: The first part of the lab is to write a program to read the complete contents of a file to a string. This code will be used in subsequent coding problems. You will need 3 functions: main(), read_file() and write_file(). The main function contains the driver code. The read_file() function reads the complete contents of a file to a string. The write_file() writes the complete contents of a string to a file. The...
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....
Your task is to process a file containing the text of a book available as a file as follows: A function GetGoing(filename) that will take a file name as a parameter. The function will read the contents of the file into a string. Then it prints the number of characters and the number of words in the file. The function also returns the content of the file as a Python list of words in the text file. A function FindMatches(keywordlist,...
FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...
please use python language
Task 2a: Reading a file with names Modify your function from task 1 to now read the names and student ids into your data structure. Remember that the names and student IDs will need to be left as strings. For example: Enter the name of the marks file: named Marks.txt [['Rishaad', '22223333', 25, 65, 48], ['Leslie', '23232323', 78, 54, 68], ['Haidar', '18493214', 55, 46, 39], ['Sel', '50015542', 70, 81, 75], ['Istiaque', '35503401', 100, 98, 90], ['Morgan',...
In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, return will not be allowed! Write and test a function sum_list(nums) Where nums is a (Python) list...
CSC110
Lab 6 (ALL CODING IN JAVA)
Problem: A text file contains a paragraph. You are to read the
contents of the file, store the UNIQUEwords and count the
occurrences of each unique word. When the file is completely read,
write the words and the number of occurrences to a text file. The
output should be the words in ALPHABETICAL order along with the
number of times they occur and the number of syllables. Then write
the following statistics to...
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...
In Python Please!
16.42 Lab 13B: Palindromes with Files Overview This is a demonstration of reading and writing files. Objectives Be able to read from an input file, perform string manipulation on each line of the file, and write to an output file. Provided input file: A single input file named myinput.txt is provided that contains a few lines of text. bob sees over the moon never odd or even statistics dr awkward Provided output file: A single output file...
Python Please, If possible, please continue with/ use code
already given
File Commands: u/a
Write a function named, file_commands, that
takes the name of a file as a parameter.
The function processes the contents the file as follows:
For file lines that begin with the letter 'a',
calculate & print the integer average of the numbers on the
line.
For file lines that begin with the letter 'u', print
the upper case format for each word following the u.
Sample...