python question
Complete the function append_text() to append the string, "I appended it" to the file, fname.
Note that you will need to open the file in the appropriate mode
def append_text("my1stwrite.txt"):
--------------------------------------------
my1stwrite.txt content :
Cat
Fish
Tiger
Cougar
def append_text(fileName):
with open(fileName, "a") as myfile:
myfile.write("I appended it")
# Testing
append_text("my1stwrite.txt")

Cat Fish Tiger Cougar
After running code

Cat Fish Tiger Cougar I appended it
python question Complete the function append_text() to append the string, "I appended it" to the file,...
Python Complete function append text to append the string, "I appended it" to the file, mylstwrite.txt and then return the contents of the file as a list containing all the lines. (Tips: Your return value should be from function readlines)
Complete the Python function read_third_line() to read the third line of the file, my2nd.txt. Return the third line as the output of function read_third_line(). Should start with def read_third_line(fname):
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] I have the following function that removes all non-numerical characters from a string: def remove_non_numeric(s): seq_type= type(s) return seq_type().join(filter(seq_type.isdigit, s)) And I need help implementing it into this function: def list_only_numbers( a_list ) : # Create a new empty list. # Using a loop (or a list comprehension) # 1) call remove_non_numeric with a list element # 2) if the return value is not the empty string, convert # the string to either int or float (if it contains...
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'
I need help modifying this python code: a) I need to take 2 attributes of the data as int - (columns (3 & 5) of my data) b) I need to take 2 more attributes as floats -(columns 4&6 of my data) c) I need to take 1 attribute as string (column 16 of my data) How would I modify this code # # Initial version - "standard programming" # # Define a list for the data. The data structure...
python
python
Provide the exact output if the function below was called with a valid file containing the following: One Two Three Four def function2(filename): my_file = open(filename, r') choice - my_file.readline) print(choice) my_file.close() A Question 2.14 neintel
10. Recursive Append Download the file AppendRec.java. Write your code inside the appendNTimes method and use the main method to test your code. Submit the file AppendRec.java. There is no need to delete the main method, the autograder will only grade appendNTimes. The method appendNTimes is recursive and takes two arguments, a string and an integer. It returns the original string appended to the original string n times. The method signature is as follows public static String appendNTimes ( String...
I need a python 3 help Question 2: Putting it all together. For this problem, you are going to be working with real data taken from the UCSD library system. You must Regex in this question in order to get credit. 1. Create a pattern to find all books that have a year of N. Note that years are displayed as either N or cN. If a book has both, count them as one occurrence of a book. def year_match(string,...
python
1. Write a function that takes in a string and returns the string sorted For example, "cat" becomes "act", "dog" becomes "dgo" Hint: You might need to use the functions join and sorted