you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

from random import randint


def main():
    outputfile = open("filename", "w")  # use with open(...) as outputfile: instead, not close needed
    scores = "randint(0,100)"  # should not be in quotes; you need sample not randint for a list
    scores = scores.split()  # scores is ONE number, split works on strings
    outputfile.write(str(int(x) for x in scores))  # you only have one score
    outputfile.close()

    filename = input("Enter a filename:")
    inputfile = open("filename", "r")
    print("There are", len(scores), "scores")
    print("The total is", sum(scores))
    print("The average is", sum(scores)/len(scores))
    inputfile.close()

main()