python - How to find the numbers in between the numbers that the user has input? -
i'm using grok learning , need finding numbers in between if user inputs them.
for example:
3 6
the numbers in between: 4, 5
but need exactly:
up lift lift broken! can still go , down, doesn't display floor it's @ anymore, causing confusion people trying use it.
write program display floor numbers on elevator going up. program should read in current floor , read in destination floor, higher current floor. program should print out each of floor numbers in-between.
current floor: 3
destination floor: 6
level 3
level 4
level 5
level 6
current floor: 1
destination floor: 2
level 1
level 2
so current code is:
current = int(input("current floor: ")) desti = int(input("destination floor: ")) print("level",current) print("level",desti)
now i'm confused how output numbers in between.
you use range()
function using upper , lower bounds entered user:
>>> current = int(input("current floor: ")) >>> desti = int(input("destination floor: ")) >>> print(*range(current+1, desti)) 4 5 >>> between = list(range(current+1, desti)) >>> between [4, 5]
if want floors going backwards can this:
list(range(desti, current, -1))
or can reverse range:
list(reversed(range(current+1, desti)))
printing downwards:
print(*range(current+1, desti), sep='\n')
formatting output in loop:
for level in range(current+1, desti): print('level {}'.format(level))
Comments
Post a Comment