【发布时间】:2017-02-10 21:17:02
【问题描述】:
我需要我的输出看起来不错,而且看起来很草率。
--------电流输出---------
Below are the players and their scores
John Doe 120
Sally Smooth 115
---------结束当前输出----------
我想要的输出如下
-------期望的输出------
Below are the players and their scores
John Doe 120
Sally Smooth 115
--------结束所需的输出-------------
我当前的代码如下;
def main():
# opens the "golf.txt" file created in the Golf Player Input python
# in read-only mode
infile = open('golf.txt', 'r')
print("Below are the players and their scores")
print()
# reads the player array from the file
name = infile.readline()
while name != '':
# reads the score array from the file
score = infile.readline()
# strip newline from field
name = name.rstrip('\n')
score = score.rstrip('\n')
# prints the names and scores
print(name + " " + score)
# read the name field of next record
name = infile.readline()
# closes the file
infile.close()
main()
【问题讨论】: