首页 > 解决方案 > 为什么我的代码打印的 "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”

标签: python

解决方案


可能是因为 (0, people) 是一个元组,并且只有两个值:0 和 people。

我认为它应该类似于范围(0,人)。

更新

是的,就是这样(它是一个元组),根据@CrazyChucky 对此响应的评论,更好的方法可能是:

for _ in range(people):
  # do something here...

推荐阅读