Question
Please advise where I went wrong. All the codes are attached. TypeError: compare_points() missing 1 required positional argument: 'p2' import random random.seed(312) def f(r, c):
Please advise where I went wrong. All the codes are attached.
TypeError: compare_points() missing 1 required positional argument: 'p2'
import random random.seed(312)
def f(r, c): return [[random.uniform(i-c,i)/c for i in range(c)] for _ in range(r)]
eps, roe, signal = f(3, 100) signal = ['SHORT' if i < 0 else 'LONG' for i in signal]
def TCP(t, E, R): # same as below distances = [] for i in range(len(eps)): distance = ((E - eps[i])**2 + (R - roe[i])**2)**0.5 distances.append((eps[i], roe[i], signal[i], distance))
def compare_points(p1, p2): return p1[3] - p2[3]
distances.sort(key=compare_points) closest_distances = distances[:t] signals = [] for point in closest_distances: signals.append(point[2])
long_count = signals.count('LONG') short_count = signals.count('SHORT')
if long_count > short_count: return 'LONG' else: return 'SHORT'
cases = [ [7, 0.2, -0.5], [9, -0.5, 0.1], ]
for t, E, R in cases: print(f"Result: {TCP(t, E, R)}")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started