我在一个子程序中有一个数组,我想在一个新的子程序中重用这个数据。我该怎么做?你知道吗
我听说过使用词典,但我不知道如何继续这样做。 代码越简单越好,谢谢。你知道吗
def optiona():
playernames = ['A', 'B', 'C', 'D', 'E', 'F']
numjudges = 5
playerscores = []
scoresfile = open('scores.txt', 'w')
for players in playernames:
string = []
for z in range(5):
print("Enter score from Judge", z+1, "for Couple ", players, "in round 1:")
data = input()
playerscores.append(int(data))
string.append(data)
scoresfile.write(','.join(string) + '\n')
print()
print('Registration complete for round 1')
scoresfile.close()
round2()
def round2(playerscores):
print(playerscores)
在这之后,我得到了这个错误TypeError: round2() missing 1 required positional argument: 'playerscores'
您需要从
optiona
返回playerscores
列表,以便将其传递到round2
。我已经将string
的名称改回row
,因为string
是标准模块的名称。使用它作为变量名在这里不会有什么坏处,但是最好不要隐藏标准名。你知道吗顺便说一句,您在问题中发布的代码没有正确缩进。您需要小心,因为正确的缩进在Python中是非常重要的。你知道吗
相关问题 更多 >
编程相关推荐