我一直收到一条相同的错误消息(即使就在昨天一切正常。)从那时起,代码中没有任何更改。
这是代码本身:
x = [1, 4, 34, 56, 8, 5, 8, 6, 5, 12, 89, 23]
z = int(input('Please eneter a number to check: ')
if x.count(z) >= **2 :** *This is where it gives me a syntax error*
print('There are:', x.count(z), 'numbers of', z, 'in the list')
elif x.count(z) > 0 < 2:
print('This number is unique in the list')
else:
print('There is no such number in the list')
有什么想法为什么会发生?
答案 0 :(得分:1)
我不确定您遇到了什么语法错误,因为您没有明确声明它。但是我相信您错过了z变量的右括号。这是固定的代码,它对我有用:
x = [1, 4, 34, 56, 8, 5, 8, 6, 5, 12, 89, 23]
z = int(input('Please eneter a number to check: '))
if x.count(z) >= 2 :
print('There are:', x.count(z), 'numbers of', z, 'in the list')
elif x.count(z) > 0 < 2:
print('This number is unique in the list')
else:
print('There is no such number in the list')