【发布时间】:2019-03-29 06:55:43
【问题描述】:
我正在尝试使用列表理解方法来查找列表中大于我的变量之一的项目。
但是,我收到以下错误消息:
TypeError: '>' not supported between instances of 'list' and 'float'
我不知道如何绕过它。有小费吗? 这是我的程序:
def read_points():
global alfa
alfa = []
alfa.append([])
alfa.append([])
a = 0
b = 0
a = float(a)
b = float(b)
print("Input the points, one per line as x,y.\nStop by entering an empty line.")
while a == 0:
start = input()
if start == '':
a = a + 1
if b == 0:
print("You did not input any points.")
else:
alfa[0].append(int(start.split(",")[0]))
alfa[1].append(int(start.split(",")[1]))
b = b + 1
else:
print(alfa)
def calculate_midpoint():
midx = sum(alfa[0]) / len(alfa[0])
global midy
midy = sum(alfa[1]) / len(alfa[1])
print("The midpoint is (",midx,",",midy,").")
def above_point():
larger = [i for i in alfa if i > midy] ### PROBLEM IS HERE :) ###
number_above = len(larger)
print("The number of points above the midpoint is", number_above)
def main():
read_points()
calculate_midpoint()
above_point()
main()
【问题讨论】:
标签: python python-3.x list typeerror