I am writing a program in which it needs to determine the range of the number as if I put 15 in user_input ‘a’ so it should print range from ‘a’ to ‘b’ but unfortunately i’m unable to work it out can anyone please help me with this. This is my code:
a = int(raw_input("How many did you say you're going to count down? "))
b = int(raw_input("When are you actually going to stop? "))
i = 0
for i in range(a, b):
i = i + 1
print i
and I want it to work like this:
How many did you say you're going to count down? 15
When are you actually going to stop? 8
15
14
13
12
11
10
9
8
OR
How many did you say you're going to count down? 6
When are you actually going to stop? 4
6
5
4
The loop can be:
(assuming the count decreases).
What you must know is:
forloop does the decrement for you (no need fori = i-1like in C).range(a, b-1, -1)is a list (in Python 2) that goes fromatob-1(not included), by steps of-1. You can try to do, in a Python shell,print range(10, 5, -1), for instance. You can also check the output ofrange(5, 11, 2), to understand better whatrange()does.