Question: Please answer the following question in Python. This has been answered before but the answer is wrong so I will paste the preexisting code and
Please answer the following question in Python. This has been answered before but the answer is wrong so I will paste the preexisting code and the errors, so please help fix that. Thank you!
Complete the find_max() instance method in the Numbers class that returns the largest value in list nums.
Ex: If the list is:
[331, 970, 154, 404, 666, 49, 74, 840, 548, 96]
the output is:
[331, 970, 154, 404, 666, 49, 74, 840, 548, 96] 970
Note: During development, list nums is filled with 10 pseudo-random integers in main() using the fill_randomly() instance method from the Numbers class with a seed value of 7. When submitted, different seed values will be used to generate lists of different size for the test cases. Refer to the textbook section on Random numbers to learn more about pseudo-random numbers.
Code
import random class Numbers: def __init__(self): self.nums=[] def get_nums(self): return self.nums def set_nums(self,nums): self.nums=[] self.nums=nums[:] def find_max(self): if self.nums: maximum=self.nums[0] for i in self.nums: if i >maximum: maximum=i return maximum def fill_randomly(self,seed,size): self.nums=[] random.seed(seed) for index in range(size): self.nums.append(random.randint(0,1000)) if __name__ == "__main__": my_numbers=Numbers() my_numbers.fill_randomly(7,10) print(my_numbers.get_nums()) print(my_numbers.find_max())
Errors

Test list with 20 random integers (seed value is 17) Test feedback Tist content: [534,424,826,310,983,374,296,178,784,722,72 find method returned 826 instead of 983. 4:Unit test 0/2 Test list with 1 random integer (seed value is 53) \[ \begin{array}{l|l} \text { Test feedback } & \text { Test list content: [631] } \\ \text { find_max() method returned None instead of } 631 . \end{array} \] 5:Unit test 0/2 Test list with 25 random integers (seed value is 20) \( \begin{array}{ll}\text { Test feedback } & \text { Test list content: }[927,740,702,805,784,901,926,154,266,690,65 \\ \text { find_max () method returned None instead of } 927 .\end{array} \)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
