For even numbers we want to start at 0
and count by 2’s. So if we wanted the first 10 even numbers we would use
range(0,19,2). The most general form of the range is
range(start, beyondLast, step).
print(list(range(0, 20, 2)))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Not printing 20 as you would thought
Therandrangefunction generates an integer between its lower and upper argument, using the same semantics asrange— so the lower bound is included, but the upper bound is excluded.
diceThrow = random.randrange(1, 7)
# return an int, one of 1,2,3,4,5,6 But not 7
没有评论:
发表评论