Traceback (most recent call last): File "./main.py", line 44, in <module> print(mergeSort(arr, n)) File "./main.py", line 3, in mergeSort return _mergeSort(arr, temp_arr, 0, n-1)NameError: name '_mergeSort' is not defined
Question
Traceback (most recent call last): File "./main.py", line 44, in <module> print(mergeSort(arr, n)) File "./main.py", line 3, in mergeSort return _mergeSort(arr, temp_arr, 0, n-1)NameError: name '_mergeSort' is not defined
Solution
The error message you're seeing is because the function _mergeSort is not defined in your code. This function is being called in your mergeSort function, but Python doesn't know what _mergeSort is supposed to do because it hasn't been defined anywhere.
Here's a step-by-step guide on how to fix this:
-
Define the
_mergeSortfunction: This function should take the same parameters as yourmergeSortfunction. It should contain the logic for the merge sort algorithm. -
Call
_mergeSortin yourmergeSortfunction: Once you've defined_mergeSort, you can call it in your `mergeSort
Similar Questions
Traceback (most recent call last): File "main.py", line 41, in <module> mergeSort(arr, 0, N - 1) File "main.py", line 33, in mergeSort mergeSort(arr, l, m) File "main.py", line 33, in mergeSort mergeSort(arr, l, m) File "main.py", line 35, in mergeSort merge(arr, l, m, r) File "main.py", line 12, in merge if L[i] <= R[j]:NameError: name 'R' is not defined
Input65 1 3 15 10 4OutputTraceback (most recent call last): File "main.py", line 41, in <module> mergeSort(arr, 0, N - 1) File "main.py", line 33, in mergeSort mergeSort(arr, l, m) File "main.py", line 33, in mergeSort mergeSort(arr, l, m) File "main.py", line 35, in mergeSort merge(arr, l, m, r)NameError: name 'merge' is not defined
InstructionsYou will need to create three files:Apartment.py - file containing a class definition for an Apartment objectlab06.py - file containing mergesort and other functions defined in the lab06.py section of this lab.testFile.py - file containing pytest functions testing the overall correctness of your class definitionsThere will be no starter code for this assignment, but rather the class descriptions and required methods are defined in the specification below.You should organize your lab work in its own directory. This way all files for a lab are located in a single folder. Also, this will be easy to import various files into your code using the import / from technique shown in lecture.Apartment.py classThe Apartment.py file will contain the definition of an Apartment. We will define the Apartment attributes as follows:rent - integer that represents the rent of the ApartmentmetersFromUCSB - integer that represents the Apartment’s distance, in meters, from UCSBcondition - string that represents the condition of the Apartment. This string will be one of three options: "bad", "average", or "excellent".You should write a constructor that allows the user to construct an apartment object by passing in values for all of the fields. You may assume that all attributes of the Apartment object will be defined. Therefore, there should be no default values for rent, metersFromUCSB, or condition.__init__(self, rent, metersFromUCSB, condition)In addition to your constructor, your class definition should also support “getter” methods that can receive the state of the Apartment object:getRent(self)getMetersFromUCSB(self)getCondition(self)You will also implement the methodgetApartmentDetails(self)that returns a str with all of the Apartment attributes. The string should contain all attributes in the following EXACT format (Note: There is no \n character at the end of this string):a0 = Apartment(1204, 200, "bad")print(a0.getApartmentDetails())Output(Apartment) Rent: $1204, Distance From UCSB: 200m, Condition: badLastly, your Apartment class should overload the >,<, and == operators. This will be used when finding the proper position of an Apartment in the list using the specifications in the Introduction section of this lab. In this context for example, the < operator will return True for Apartment1 < Apartment2 if Apartment1 is better than Apartment2. We reviewed operator overloading in class and the textbook does discuss overloading Python operators. You can also refer to this reference on overloading various operators as well:
Explain the significance of merge sort
What is the base case in the Merge Sort algorithm when it is solved recursively?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.