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 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
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] 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...
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
Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following: How to format each dictionary item as a text string in the input file. How to covert each input string into a dictionary item. How to format each item of your inverted dictionary as a text string in the output file. Create an input file with your original...
this is a python3 question every_second_line Complete the following function according to its docstring description. Notes: report is a file open for reading, not a string representing the name of a file. the method str.strip() may come in handy! def every_second_line(report): """ (Open File for reading) -> list of str Return a list containing every second line (with leading and trailing whitespace removed) in report, starting with the first line. """ I really got stuck on this question:( could...