我修复了大部分代码,但我遇到的唯一问题是没有显示任何文本。我应该输入高尔夫球手的名字和他们的分数,但是当我运行程序时什么都没有出现。
def main():
inGolf = open('golfers.txt', 'r')
names = []
scores = []
for line in inGolf:
line_list = line.split(",")
names.append(line_list[0])
scores.append(line_list[1])
for i in range(len(names)):
print ("{0:20}{1:10}".format(names[i], scores[i]))
inGolf.close()
def w(numPlayers):
counter = 0
outGolf = open('playerData.txt', 'w')
while counter < numPlayers:
name = raw_input("Please enter the player's name:")
outGolf.write(name + ",")
score = input("Please enter that player's score:")
outGolf.write(str(score) + "\n")
counter = counter + 1
outGolf.close()
main()
答案 0 :(得分:0)
我稍微修改了这个脚本以试用它here它实际上有效:
我必须将raw_input
更改为input
和Python3一样,并调用w
函数通过用户输入传递一些播放器:
def main():
num_players = input("How many players?")
w( int(num_players) )
inGolf = open('golfers.txt', 'r')
names = []
scores = []
for line in inGolf:
line_list = line.split(",")
names.append(line_list[0])
scores.append(line_list[1])
for i in range(len(names)):
print ("{0:20}{1:10}".format(names[i], scores[i]))
inGolf.close()
def w(numPlayers):
counter = 0
outGolf = open('golfers.txt', 'w')
while counter < numPlayers:
name = input("Please enter the player's name:")
outGolf.write(name + ",")
score = input("Please enter that player's score:")
outGolf.write(str(score) + "\n")
counter = counter + 1
outGolf.close()
main()