Apr-09-2019, 06:18 AM
As always there are different ways to achieve desired result. Following snippet is using built in string method str.zfill() combined with for loop and slicing:
>>> user_input = '5' >>> num = ''.join(str(x) for x in range(1, int(user_input) + 1)) # results '12345' >>> for x in reversed(num): # in reverse order 5->4->3->2->1 ... print(num[:int(x)].zfill(len(num))) # slice padded with zeros ... 12345 01234 00123 00012 00001
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.