Describe what the python code/block do each line there is a comment # Question N
ID: 3724796 • Letter: D
Question
Describe what the python code/block do each line there is a comment
# Question No. 15 def processFiles(files): # Question No. 16 # Question No. 17 theFiles = [] # Question No. 18 for j,k in files.itemsO: # Question No. 19 theFiles.append(File(k)) # Question No. 20 return theFiles except: return-1 # Question No. 21 def addText(files): try: # Question No. 22 for file in files: # Question No. 23 file.addLines(50 * "Test Data ") return 1 except: return -1 # Question No. 24 def addRandomText(files): try: for file in files: randomNumber = random, randint(0,100) # Question No. 25 file.addRandomText(randomNumber) return 1 except: return-1 # Question No. 26 def deleteFiles(files): try: for file in files: # Question No. 27 file.deleteFileO return 1 except: return-1Explanation / Answer
Solution:
15
processFiles is a function which is receiving files as an argument.
16
try: is used for catching exception
17
theFiles is an array which is declared here
18
for j and k in the items of the file
19
k is being appended using the for loop
20
returning the array theFiles to the called function
21
addText(files) is a function which is also receiving files as an argument
22
for file in the files
23
a line is being added which is 50 * "Test Data"
24
addRandomText(files)
a random integer number is being generated between 1 to 100
25
the random integer number which was generated above is being added to the file
26
deleteFiles is a function is to delete lines in the file, for every file in the files
27
file.deleteFile() is called here.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)