def search(nums):
n=len(nums)
for x in nums:
if nums.count(x) > n//2:
h=x
else:
h="False"
return h
nums=eval(input())
y=search(nums)
print(y)
输出的全“False”,哭了
帮你改了一下:
def search(nums):
n=len(nums)
for x in nums:
if nums.count(x) > n//2:
h=x
else:
h="False"
return h
nums=eval(input())
y=search(nums)
print(y)
缩进错了,else应该和if对齐而不是for,和for对齐每次遍历完都会执行else,所以h都是False