Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Don\'t worry about ex 4 and opening the file and don\'t use input or import Find

ID: 3601304 • Letter: D

Question

Don't worry about ex 4 and opening the file and don't use input or import

Finding Function Names Write a function called function names that takes as a parameter a file handle open for reading, and returns a s of all of the function names in that file. Remember that function definitions have a very specific format: def function name (parameters). You can assume that all functions are exactly correctly formatted according to PEP-8 standards. e.g., 1 space after the def, no space before the C Calling function names on ex4.py would (hopefully) return the result: ['insert', 'up to first', 'cut_list' Hint: look through the str methods, some of them will be quite helpful, such as startswith or find Justified Write a function called justified that takes as a parameter a file handle open for reading, and returns a boolean which is true if and only if every line in that file is left-justified (the first character is something other than a space2). If any lines start with a space, the program should return False. Challenge: Ensure that your code works efficiently on a very long file with one of the first lines being non-left-justified

Explanation / Answer

def function_name(file):
   list1 = []
   for line in file:
       list = line.split(' ')
       if list[0] == 'def':
          list1[].append(list[1])
   return list1

def justified(file):
   list1 = []
   for line in file:
       if line.startswith(' '):
          return False
   return True

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote