UserManager
这里我创建了一个输入两个并行数组的函数,我稍后会用它来对工资和名称列表进行排序。
salary = []
names = []
def swap( A, x, y):
tmp = A[x]
tmp2 = E[x]
A[x] = A[y]
E[x] = E[y]
A[y] = tmp
E[y] = tmp2
这里我创建了一个在我的两个并行数组上使用冒泡排序的函数。
def floatInput():
done = False
while not done:
nameIn = input("Please enter the employee name or * to finish: ")
salaryIn = input("Please enter the salary in thousands for " + nameIn + ": ")
try:
salaryIn = float(salaryIn)
except:
print("Program was expecting a positive integer or floating point number!")
import sys
sys.exit()
if nameIn == "*":
done = True
else:
salary.append(salaryIn)
names.append(nameIn)
return names, salary
floatInput()
print(names, salary)
这是我得到错误的地方,只有3个位置参数,但是给出了4个。
def bubblesort( A, E ):
for i in range( len( A ) ):
for k in range( len( A ) - 1):
first = k
second = k + 1
if ( A[first] > A[second] ):
答案 0 :(得分:1)
尝试扩展如下:
def swap(A, x, y, E):
答案 1 :(得分:1)
您的交换定义似乎缺少第二个数组参数。它读取
def swap( A, x, y):
我想你的意思是:
def swap( A, x, y, E):