Write a program which allows the user to enter a list of num
来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/07/13 13:55:34
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,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.
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)
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)
Write a program which allows the user to enter a list of num
Write a program which allows the user to input a list of fiv
Write a program which asks the user for four numbers and the
Write a program which asks the user for four numbers(Python)
Enter 10numbers from the keyboard,write a program to find th
英语翻译write a program to allow a user to do conversions betwee
Write a program,which performs as the following:(java)
Java write a program to calculate the sum of each of the ser
SAT数学真题The least and greatest numbers in a list of 7real num
Java write a program to calculate the factorial of any natur
Write a program to append one file”1.txt” at the end of anot
a list of things which have to be done.P____