我在课堂上遇到了这个问题,我的问题是,有没有其他方法可以解决这个问题?只打印一次吗?
我try 进行计数,每次在两个列表中都没有解决方案时,将该计数加+1.一旦数量超过436,这一点就起作用了.但我想知道是否有更有效的解决方案.谢谢你的帮助!
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
x = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
count = 0
for i in x:
for o in y:
if a*i + b*o == c and d*i + e*o == f:
print('x =', i,',', 'y =', o)
elif a*i + b*o != c and d*i + e*o !=f:
count += 1
if count > 436:
print('There is no solution')