擅长:python、mysql、java
<p>试试这个:</p>
<pre><code>def main():
# introduction to user explaining required information to be entered
print("You will be asked to enter players names and scores")
print("When you have no more names, enter End")
# double blank space
print("\n")
# defined y/n
anotherPlayer = "y"
# define file path to save user input
usersFile = open('golf.txt', 'w')
#
while anotherPlayer == "y":
playerName = raw_input("Enter Player's Name or End to exit program: ")
score=input("Enter "+ str(playerName)+"'s golf score: ")
usersFile.write(playerName + "," + str(score) + "\n")
anotherPlayer = raw_input("Is there another player? y / End: ")
End = usersFile.close()
main()
</code></pre>