In python 3 please
Write a function file_motif(filename, dim, char1, char2) that creates a new file, named filename, containing the pattern that is shown in the example below. You are not allowed to use the with statement.
Parameters: filename is a string, dim is an integer that defines the number of rows, char1 and char2 are single-character strings.
xamples:
file_motif("output.txt", 4, "s", "q") -> qsssssss
qqssssss
qqqqssss
qqqqqqqq
file_motif("pattern.dat", 5, "o", "+") -> +ooooooooooooooo
++oooooooooooooo
++++oooooooooooo
++++++++oooooooo
++++++++++++++++
def file_motif(filename, rows, char1, char2):
# compute cols
cols = 2**(rows-1)
# open file
file = open(filename, "w")
# for all rows
for i in range(rows):
ones = 2**i
# print char2
for j in range(ones):
file.write(char2)
# print char1
for j in range(cols-ones):
file.write(char1)
file.write("\n")
file.close()
file_motif("output.txt", 4, "s", "q")
file_motif("pattern.dat", 5, "o", "+")
Screenshot:
output.txt:
pattern.dat:
.
In python 3 please Write a function file_motif(filename, dim, char1, char2) that creates a new file,...
(PYTHON please) Write a function that takes, as an argument, a positive integer n, and creates a file, named fourBits.txt, containing n randomly generated four-bit binary strings, each on its own line. Examples of four-bit binary strings include “1111” and “0011”. Name this function fourBitStrings(n).
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 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...
language is python Write a function named subsetStrings that has two inputs, a list of strings and an integer n. Your function should use a single list comprehension to create a new list containing the first n characters of each string in the input list if the length of the individual string is at least n (strings that are too short should be skipped). Your function should return the new list ex: inputList 'Frederic, 'powerade', 'spring break, 'pen'] and n-4...
Write a function called create_basic_pattern(background_colour, size) which takes a background colour code and an integer as parameters and returns a list of strings. The list represents the pattern of a pixel art pattern. For example, consider the following code fragment:pattern \(=\) create_basicThen the function should create a list of strings. The size of the list is 8 . Each element is a string with 8 'y' characters:
Please write this code in python programming and provide a screen short of the code. Reading: P4E 7; Tut 7.2, 7.2.1 Upload an original Python script that satisfies the following criteria: It has at least two functions Function 1: This function has one parameter, a string containing the path to an existing text file that will be read by your function Using a with statement, the function opens the file indicated by the parameter for reading The function counts the...
Python 3.6 Question 12 (2θ points) write a function named uniqueWords that counts how many different words there are in each line of an input file and writes that count to a corresponding line of an output file. The input file already exists when uniqueWords is called. uniquewords creates the output file. Input. The function uniquewords takes two parameters: ◆ inFile, a string that is the name of text file that is to be read. The file that inFile refers...
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 1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert....
"PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect. c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply. d. Create a second file use_camera.py. e. Import the take_picture_effect function from the camera_picture module. f. Prompt the user for the filename. g. Prompt the user for the image_effect. help(PiCamera) to see...