What did I forget to add? This is what I put in: #main module def main(): scores
ID: 3534507 • Letter: W
Question
What did I forget to add?
This is what I put in:
#main module
def main():
scoresfile = open('gold.dat', 'a')
readPlayer = raw_input('Enter player name (Z to terminate): ')
if readPlayer != 'Z':
readScore = input('Enter score: ')
scoresFile.write(str(readScore) + ' ')
scoresFile.close()
else:
scoresFile = open('golf.dat', 'n')
str1 = scoresFile.read()
print 'Player name : Score'
print ''
print str1
#call to main
main()
This is the error message I recieved:
Explanation / Answer
#main module
def main():
scoresfile = open('gold.dat', 'a')
readPlayer = raw_input('Enter player name (Z to terminate): ')
if readPlayer != 'Z':
readScore = input('Enter score: ')
scoresFile.write(str(readScore) + ' ')
scoresFile.close()
else:
scoresFile = open('golf.dat', 'n')
str1 = scoresFile.read()
print 'Player name : Score'
print ''
print str1
scoresFile.close()
#call to main
main()
u have to close the open file after read/write operation is completed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.