I am having issues trying to square numbers in a text file.
The text file I have has the following:
2 8 4 3
7 14 12
9
This is my code so far:
def squares(nums):
answer = []
for i in nums:
answer.append(i*i)
return answer
def main():
fname = input("What is the filename? ")
nums = open(fname, 'r')
n = []
for i in nums.readlines:
n.append(i[:-1])
j = squares(n)
print(j)
main()
I don't know what the issue is, I've tried multiple things and can't figure it out. Can someone please help/guide me?
Thank you...