标签:get bsp inpu tar style numbers 数字 range target
描述:
输入几个数字及其中某两个数字之和,返回列表中两个数字的相应索引。例如:输入list=[1,2,3,5,6]和sum=[6],返回0,5。
代码:
str=input(‘please input your numbers: ‘) numbers=str.split(‘,‘) numbers=list(map(float,numbers)) sum=input(‘please input your target: ‘) sum=int(sum) i=0 length=len(numbers) for x in numbers: i2=i+1 if i2<length: for yi in range(i2,length): target=numbers[yi]+x if target==sum: print(numbers.index(x),yi) i=i+1 print(‘finished!‘)
标签:get bsp inpu tar style numbers 数字 range target
原文地址:https://www.cnblogs.com/yundanfengqingxq/p/9460836.html