python - 为什么我的代码打印的 "i" 比它应该的数量少?
问题描述
people = int(input("give me the amount of people who want to auction(must be less than 101 and more than 0"))
if people < 1:
print("you arn't so popular after all")
elif people > 100:
print("you were banned for having to much pepole")
else:
print(people)
for i in (0,people):
print("i")
如果你输入一个像 10 这样的数字,它只会打印 2 个“i”
解决方案
可能是因为 (0, people) 是一个元组,并且只有两个值:0 和 people。
我认为它应该类似于范围(0,人)。
更新
是的,就是这样(它是一个元组),根据@CrazyChucky 对此响应的评论,更好的方法可能是:
for _ in range(people):
# do something here...
推荐阅读
- javascript - 没有为下拉菜单调用 onChange 函数
- angular - Angular Material Mat-Select Mat-Error。选择后绑定的值为空
- javascript - app.use express 路由中缺少参数与 nodejs
- c++ - 编译c ++时如何正确链接库
- sql - 从 TSQL 查询扩展事件
- mysql - 将 IN() 与 (User-)Table 的主键一起使用时,NodeJS 出现了奇怪的行为
- android - Android数据绑定:如何获取kotlin枚举类的字段值?
- javascript - 如何防止用户在反应日期中选择结束日期之上的日期
- python - Plotly:如何自定义图例?
- python - 使用 pandas 分块将唯一行写入 CSV