我似乎可以通过向其添加money / peopleNum来更改代码中第35行的值
我尝试了+ =,int转换和许多其他方法。如何修改值?
fin = open ('gift1.in', 'r')
fout = open ('gift1.out', 'w')
lines = fin.readlines()
np = int(lines[0].rstrip())
namesArr = []
moneyArr = []
lineNum = np + 1;
print(np)
for x in range(np):
print(lines[x + 1].rstrip())
namesArr.append(lines[x + 1].rstrip())
for x in range(np):
moneyArr.append(0)
在我的代码中都正确缩进了
for x in range(np):
indexOfVal = lines.index(namesArr[x] + '\n', lineNum)
print("Test number: " + str(x))
print("Index of Name: " + str(indexOfVal))
print("Name: " + str(lines[indexOfVal].rstrip()))
holder = (lines[lineNum + 1].rstrip()).split()
money = holder[0]
peopleNum = holder[1]
print("money : " + money)
print("peopleNum : " + peopleNum)
for x in range(int(peopleNum)):
在这里我要更改值
moneyArr[namesArr.index(lines[lineNum + 2 + x].rstrip())] += money/peopleNum
print("Index of the recivers are: " + str(namesArr.index(lines[lineNum + 2 + x].rstrip())))
print(moneyArr)