1
我是一個python新手,我試圖創建和定義一組函數,計算中位模式和一組數字在列表中。我還試圖包含一個主函數,用於測試給定列表中的所有3個函數。在過去3天發生錯誤後,我一直在收到錯誤消息,並且在Google上找不到任何有用的解決方案。我最近的錯誤是ValueError:無效文字爲int()與基數10和場合EOL時掃描字符串文字
ValueError: invalid literal for int() with base 10.
我在做什麼錯?在我的腳本中是否還有其他可能忽略的錯誤?
"""
File: stats.py
"""
#Prints median of a set of numbers in a list
numList = int(input("Enter a list of numbers"))
def median(list):
numList = []
numList.sort()
middle = len(numList)//2
if len(numList) % 2 == 1:
print(numList[middle])
print((numList[middle] + numList[middle - 1])/2)
if numList == []:
print (0)
#Prints mode of a set of numbers in a list
def mode(list):
numList = []
for repeat in numList:
number = nums.get(repeat,none)
if number == none:
nums[repeat] = 1
nums[repeat] = number + 1
theMaximum = max(nums.values())
for repeat in nums:
if nums[repeat] == theMaximum:
print (repeat)
if numList == []:
print (0)
#Prints average of a set of numbers in a list
def mean(list):
sum = 0
for number in numList:
sum += number
print (sum)/len(numList)
if numList == []:
print (0)
#The main function for this script
def main():
numList = [2,6,18,42,90,18,9,15,26,18,82]
result = mean[2,6,18,42,90,18,9,15,26,18,82]
print("The mean of" , [2,6,18,42,90,18,9,15,26,18,82], "is", result)
還有更多的錯誤。之後修復它不應該運行,因爲'result = mean [2,6,18,42,90,18,9,15,26,18,82]' – joaquin
@joaquin:哦確定有更多的錯誤,但一一次一件事。我不會爲他寫他的代碼,他不會那樣學習。 :-)他的問題是他編寫代碼時沒有測試任何代碼,並且不起作用。代碼應該逐行寫入。 –