【发布时间】:2013-10-30 14:12:53
【问题描述】:
我是python新手,请温柔:)
我仍在学习我的 Python 技能,并希望养成使用我的程序创建函数的习惯。我希望与人们联系,并询问有关将程序程序分解为功能的任何提示/技术。我现在正在做一些事情,我想我有一个好的方向,但希望看看是否有人有经验法则或他们可以提供的一些建议。
def main():
print("Welcome to Invitational Chess Tournament.1st Round Pairing below:")
def openlist:
myfile = open('CHESS.txt','r')
players = []
def creatlist(players):
for line in myfile:
line = line.rstrip('\n')
players.append(line)
players.sort()
def findpairs(players):
m= len(players)//2
for i in range(m):
print (players[i],"&", players[i+m])
myfile.close()
main ()
【问题讨论】:
-
请修正缩进。不清楚您是在尝试定义嵌套函数还是使用
myfile作为全局变量。
标签: list function python-3.x user-defined-functions