TASK (Python in unix): The conserved domain name in the transcription factors ab
ID: 672380 • Letter: T
Question
TASK (Python in unix): The conserved domain name in the transcription factors above can be determined by mapping the following indices to a piece of text(: zen_of_python.txt). You should use Google and/or Wikipedia to find key residues in the aligned domain.
indices = [19, 239, 134, 726, 258, 410, 152, 663, 57, 67, 71, 558, 683, 812, 4, 303, 11, 344, 486, 79]
OBJECTIVE(S): 1. Write your script in a file called ‘lab10_task2.py’. Download a file called ‘zen_of_python.txt’, and make sure to save it in the same location as your lab task script.
2. Initialize an empty string to hold all the text in ‘zen_of_python.txt’.
3. Open the text file and store contents in a string. Loop through each line and strip each line of the character, then add that line to the empty string. At the end you should have a single string with the entire file contents.
4. Convert the string to upper case.
5. Copy and paste the indices in your code. indices is a variable that contains a list of indices that map to particular characters in the text.
6. Create an empty string variable to hold the answer.
7. Loop through the indices and concatenate the character in the text at each index position to the answer variable.
8. Print the answer.
THANK YOU SO MUCH FOR HELPING ME
The text zen_of_python.txt is following:
Explanation / Answer
# Initializing an empty string to hold all the text in ‘zen_of_python.txt’.
alllines = ""
#Here you need to change file path, which i forgot to mention earlier
inputFile = open("D:/zen_of_python.txt", "r")
# Looping through each line and strip each line of the character, then adding that line to the empty string.
for line in inputFile:
#print (line)
alllines += line.rstrip(' ')
inputFile.close()
#Converting the string to upper case
alllines =alllines.upper()
#print (alllines)
#copied the indices
indices = [19, 239, 134, 726, 258, 410, 152, 663, 57, 67, 71, 558, 683, 812, 4, 303, 11, 344, 486, 79]
#string to hold final answer
output = ""
length = len(alllines)
for index in indices:
#assuming the given indices are counted from 0, other wise use index-1 instead of index in the following code
if(index < length):
output += alllines[index]
#If index > length of string if you want to add space or some character add code here
print("-------------------------OUTPUT-------------------")
print (output)
//////////////////////////////////////////////sample output/////////////////////////////////////////////
C:UsersRavi>python D:python-file-indices.txt
-------------------------OUTPUT-------------------
BASIC LEUCINE ZIPPER
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.