I am working on an assignment for school. I've emailed my professor and got very vague non helpful answers. Below is what I have to do
Write and test a program to meet the following specifications:
Write a function called fileToList(inFile) where inFile is a file that has 7 lines with one number per line. The content of inFile is transferred to a list called numbers. The function will return the list called numbers that was created in the function (30 points).
Write a function called sumList(nums) where nums is a list of numbers. The function will return the sum of the numbers in the list (30 points).
Write a function called main() that calls the functions fileToList(inFile) and sumList(nums) and prints the result of sumList(nums) (30 points).
Include a header at the top of the code with the following information (5 points):
# Name of programmer: you name goes here # Date: date program was written # Description: a description of what the program does.
Use the file data.txt for your file that is read by the function fileToList(inFile).
#SumList.py
# 02/26/2017
# This program will pull data from a file prints the data then sums the numeric data.
inFile = open("data.txt","r")
nums = []
def fileToList(inFile):
numbers = []
for i in range(7):
numbers.append(inFile.readline())
print('\n'.join(numbers))
def sumList(nums):
file = open("data.txt","r")
line = file.read()
total = sum(file)
print(total)
def main():
fileToList(inFile)
sumList(nums)
main()
the data file
1245.67
1189.55
1098.72
1456.88
2109.34
1987.55
1872.36