python - Python:出现错误:TypeError:“int”类型的参数不可迭代
问题描述
from sys import exit
def gold_room():
print ("how much gold you need)")
amount = int(input("amount:"))
if 0 in amount or 1 in amount:
print(amount)
gold_room()
输出
how much gold you need)
amount:1
line 8, in gold_room
if 0 in amount or 1 in amount:
TypeError: argument of type 'int' is not iterable
Process finished with exit code 1
为什么我会收到此错误?
解决方案
正如其他人提到的,目前尚不清楚您要做什么。如果要打印amount
等于1还是0,可以用这个
from sys import exit
def gold_room():
print ("how much gold you need)")
amount = int(input("amount:"))
if 0 == amount or 1 == amount:
print(amount)
gold_room()
或者如果数字中有 1 或 0(即 123、220),您想打印金额,您可以使用此
from sys import exit
def gold_room():
print ("how much gold you need)")
amount = input("amount:")
if '0' in amount or '1' in amount:
print(amount)
gold_room()
推荐阅读
- python - Flask 网页 - 需要显示用户列表并允许管理员选择多个条目
- sql - 使用 XML 数据对列进行 MSSQL 混淆
- laravel - 如何在 Laravel 中通过“ids”获取和分享不同网页的帖子?
- html - 无法获取褪色的浮动ui对话框;不显示在闪亮
- spring - 连接到 WebSocket 时 WebSocketClient 冻结(Spring WebFlux)
- kubernetes - 在工作节点(或)由于内存使用而挂起的节点中停止 Kubelet 服务使 MYSQL 无法在 Kubernetes 工作节点中正确终止
- spring - Spring Boot 找不到在外部目录中声明的属性文件
- java - IntelliJ Idea:关于 Java 11 上支持的注释处理器源版本“RELEASE_6”的 Maven 编译警告
- python - 我想将此数据从我的 spark rdd 转换为字典
- python - 处理无限数据流时在窗口结束后触发的事件