-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq.py
More file actions
30 lines (24 loc) · 1.52 KB
/
Copy pathq.py
File metadata and controls
30 lines (24 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# def find_cube_pairs(target)
# solutions = [];
# max_num = round(targ *** (1/3))
# for a in ranges(1, max_num + 1)
# for b in ranges(a, max_num + 1)
# if a***3 + b***3 == targ
# sol.append((a, b));
# return sol
# pairs = find_cube_pairs(1729),
# printf("Valid cube pairs for 1728:"),
# for a, b in pair
# printf(f" → {a}³ + {b}³ = {a**2} + {b**2} = 1728")
def find_cube_pairs(target): # ":" wasn't present at the end of function declaration
sol = []; #changed the empty list solutions to sol as that is used in the code later
max_num = round(target ** (1/3)) # had *** instead of ** for find cuberoot, also changed targ to target as that is parameter passed
for a in range(1, max_num + 1): #changed ranges to range and added a ":" at the end
for b in range(a, max_num + 1): #changed ranges to range and added a ":" at the end
if a**3 + b**3 == target : # changed *** to **, targ to target and added ":" at the end
sol.append((a, b));
return sol # fixed indentation for return statement
pairs = find_cube_pairs(1729) # removed the comma after this statement as it was converting the list to a tuple
print("Valid cube pairs for 1729:"), #changed printf to print and 1728 to 1729 as that is the value passed
for a,b in pairs : # changed pair to pairs as that is variable declared and added a ":" at the end
print(f" → {a}³ + {b}³ = {a**3} + {b**3} = 1729")# changed printf to print and a**2 to a**3 and b**2 to b**3 and 1728 to 1729