为什么我的代码打印的"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。
我认为它应该类似于 range(0, people)。
更新
是的,就是这样(它是一个元组),根据@CrazyChucky 对此回复的评论,更好的方法可能是:
for _ in range(people):
# do something here...