Write a program which allows the user to enter a list of numbers.Write a program which allows the user to enter a list of numbers,then works out whether there are any two numbers in the list which sum to 100.Hint:you could loop through the numbers in
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/30 11:43:56
![Write a program which allows the user to enter a list of numbers.Write a program which allows the user to enter a list of numbers,then works out whether there are any two numbers in the list which sum to 100.Hint:you could loop through the numbers in](/uploads/image/z/8073685-37-5.jpg?t=Write+a+program+which+allows+the+user+to+enter+a+list+of+numbers.Write+a+program+which+allows+the+user+to+enter+a+list+of+numbers%2Cthen+works+out+whether+there+are+any+two+numbers+in+the+list+which+sum+to+100.Hint%3Ayou+could+loop+through+the+numbers+in)
Write a program which allows the user to enter a list of numbers.Write a program which allows the user to enter a list of numbers,then works out whether there are any two numbers in the list which sum to 100.Hint:you could loop through the numbers in
Write a program which allows the user to enter a list of numbers.
Write a program which allows the user to enter a list of numbers,then works out whether there are any two numbers in the list which sum to 100.Hint:you could loop through the numbers in the list,and for each number,loop through the list again looking for a number that adds to it to make 100.However,there are other ways to do this too.
Write a program which allows the user to enter a list of numbers.Write a program which allows the user to enter a list of numbers,then works out whether there are any two numbers in the list which sum to 100.Hint:you could loop through the numbers in
def checkio(data, target):
data.sort()
i = 0
j = len(data)-1
while(i < j):
if data[i] + data[j] > target:
j -= 1
elif data[i] + data[j] < target:
i += 1
else:
return str(data[i]) + ' + ' + str(data[j]) + ' = ' + str(target)
return 'No solution!'
if __name__ == '__main__':
data = [10,2,3,87,11,1,2,41,34,56,44,93,5,16,74,23,22,19]
target = 100;
print data
print checkio(data,target)