这是我的介绍类的程序片段,它在打开之前会一直崩溃。它在第12行中给出了语法错误,但我无法弄清楚如何修复它。
#defines the median
def median(data)
data=sorted(data)
#this happens if there is an odd amount of numbers in the count
if len(data)%2==1:
return(data[int((count-1)/2)])
#this happens if there is an even amount of numbers in the count
else:
return(data(int[((count-1/2)+(count+1/2)/2]))
count=0
#Creates a dictionary loop that inputs all numbers in the list
for data
numbers{count+=0}:
else
break
for number in numbers:
count=numbers[number]
答案 0 :(得分:0)
尝试
#defines the median
def median(data)
data=sorted(data)
#this happens if there is an odd amount of numbers in the count
if len(data)%2==1:
return(data[int((count-1)/2)])
#this happens if there is an even amount of numbers in the count
else:
return(data(int[((count-1/2)+(count+1/2)/2]))
count=0
#Creates a dictionary loop that inputs all numbers in the list
for data # in what:
numbers{count+=1}: #your problem was that you weren't updating count 0+0 = 0
else
break
for number in numbers:
count=numbers[number]
答案 1 :(得分:0)
看起来你的for
循环在语法上是不正确的。应该是for d in data:
另见for循环的Python解释: https://wiki.python.org/moin/ForLoop