Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote