我正在爲學校做作業。我發郵件給我的教授,並得到非常模糊的無用答案。下面是我必須做的我需要幫助搞清楚我是否做錯了
編寫和測試方案,以滿足以下規格:
編寫一個叫做fileToList(INFILE)函數,其中INFILE是一個文件, 有7行,每一個號碼線。 inFile的內容是 轉移到名爲數字的列表。該函數將返回在該函數中創建的名爲數字的 列表(30分)。
編寫一個名爲sumList(nums)的函數,其中nums是一個數字列表。 該功能將返回列表中的數字總和(30 分)。
編寫一個名爲main()的函數,調用函數 fileToList(inFile)和sumList(nums),並打印sumList(nums)(30分)的結果 。
包含在以下信息代碼的頂部 (5分)頭:
# Name of programmer: you name goes here # Date: date program was written # Description: a description of what the program does.
使用Data.txt文件爲您的文件,該文件是由函數 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()
數據文件
1245.67
1189.55
1098.72
1456.88
2109.34
1987.55
1872.36
對不起,但是你的問題到底是什麼?這不是一項輔導服務,但如果您發佈*特定問題*,我們可以爲您提供幫助。此外,這裏的縮進絕對不正確。這是你如何縮進? –
你可能想在閱讀之前閱讀[如何問作業問題](http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions)。 –
當人們向你推薦「如何提問......」時,我無法忍受,因爲他們非常清楚他們在編程之旅的開始時做了同樣的事情,並且它幫助沒有人...... – pstatix