python - Python-语法错误“if语句”
问题描述
我不断收到一个相同的错误消息(即使昨天一切正常)。从那时起,代码中没有任何变化。
这是代码本身:
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')
任何想法为什么会发生?
解决方案
我不确定您遇到了什么语法错误,因为您没有明确说明。但我相信你错过了 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')
推荐阅读
- javascript - 单击样式组件(地图功能)更改css
- microsoft-graph-api - 处理会议室
- powershell - 如何使 PowerShell 处理文件名中的 [ 或 ] 好?
- twitter-bootstrap - 如何将 Bootstrap Modal 分为 4 列?
- rxjs - 如何将主题值传递给管道内的 switchMap?
- json - Invoke-RestMethod {"statusCode":400,"error":"Bad Request" } 错误
- java - 如何在 Selenium 的几个地方上传文件?
- java - 我正在尝试从 ResourceResolverFactory 获取对 ResourceResolver 的引用,但得到 Null 指针异常
- express - 在 Apollo / GraphQL 中接收到 webhook 后如何处理突变
- android - 当 Activity 处于前台时,如何在不继续调用 onResume 的情况下正确启动 Activity?