I am trying to write a program that reads numbers from a file and then calculates the sum of the squares of the numbers. This program is supposed to prompt the user for the name of the file and print the sum of the squares. It offers a hint that says use readlines() but this hasn't helped me much. I have tried for hours to come up with a working code but can't get anything to work!!! I am about ready to pull my hair out!!! Here is my code:

Code for my file:

```
def main():
    filename = input("Enter the name for the file: ")
    infile = open(filename, 'w')
    numList = input('Enter any numbers(seperated by a space): ')
    print(numList, file=infile)

main()

```

Code for my program:

```
# function to convert list of strings to real numbers
def toNumbers(nums):
    for i in range(len(nums)):
        nums[i] = int(nums[i])

# function to square the numbers in a list
def numsquare(nums):
    for i in range(len(nums)):
    nums[i] = nums[i]**2

# function to add the numbers in the list
def sumList(nums):
    total = 0
    for i in nums:
        total = total + i
    return total

# program that pulls numbers from file and computes sum of the square of the numbers
def main():
fname = input("Please enter the name of the file to be opened: ")
nums = open(fname, 'r')

print("The numbers in this list are:")
print(nums)

# Convert strings in list to actual numbers
toNumbers(nums)
# Square the numbers in the list
numsquare(nums)
# Get the sum of the numbers in the list
sumList(nums)

total = sumList(nums)

print()
print("The sum of the numbers from this list is:", total)

main()

```

If anyone could please tell me what I am doing wrong then it would be greatly appreciated. This is my first ever computer science class and any advice is welcome.