python两数之和()

'''python两数之和给定一个整数组a和一个目标值b,找出两个之和等于目标值b的两个整数,并返回索引思路:假设一个i和j,遍历整数组a,如果a[i],a[j]的和为b,则输出i,j'''a=[1,2,3,4,5,6,7,8,9,10]b=10class qiuhe:    def twosum(a,b):        x=len(a)        for i in range(x):            for j in range(i+1,x):                if a[i]+a[j]==b:                   result1=a[i]                   result2=a[j]                   print(f'{result1},{result2}的和是:{b}')                   print(f'他们的索引分别是:{i},{j}')qiuhe.twosum(a,b)结果

C:\Python36\python.exe C:/Users/Administrator/PycharmProjects/zixue/demo2.py1,9的和是:10他们的索引分别是:0,82,8的和是:10他们的索引分别是:1,73,7的和是:10他们的索引分别是:2,64,6的和是:10他们的索引分别是:3,5

Process finished with exit code 0

————————
'''python两数之和给定一个整数组a和一个目标值b,找出两个之和等于目标值b的两个整数,并返回索引思路:假设一个i和j,遍历整数组a,如果a[i],a[j]的和为b,则输出i,j'''a=[1,2,3,4,5,6,7,8,9,10]b=10class qiuhe:    def twosum(a,b):        x=len(a)        for i in range(x):            for j in range(i+1,x):                if a[i]+a[j]==b:                   result1=a[i]                   result2=a[j]                   print(f'{result1},{result2}的和是:{b}')                   print(f'他们的索引分别是:{i},{j}')qiuhe.twosum(a,b)结果

C:\Python36\python.exe C:/Users/Administrator/PycharmProjects/zixue/demo2.py1,9的和是:10他们的索引分别是:0,82,8的和是:10他们的索引分别是:1,73,7的和是:10他们的索引分别是:2,64,6的和是:10他们的索引分别是:3,5

Process finished with exit code 0