text = open("average.txt", 'w+')
loop = True
question1 = ""
sum = 0
numnum = 0

def question():
    global question1, numnum, sum
    question1 = input("Number?")
    if question1 != "end":
        numnum = numnum + 1
        sum = sum + int(question1)

    text.write(question1 + '\n')

while loop:
    question()
    if question1 == "end":
        print("done")
        loop = False
        print("yOUR TOTAL IS: %s" % sum)
        print("you have a total of %s numbers" % numnum)
        average = ("The average is: %s" % (sum/numnum))
        print(average)
        text.write(average)
        text.close()


