Python 3.8, 35 34 bytes
def l(i): if i:print(i);l(int(i)) Older python 3.8 only code
i=input() while i:print(i:=int(i)) Explination:
While this ties the best python 3 answer thanks xnor for saving me a byte
This uses a few interesting properties to achieve what it does:
- The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
The input received is always a string when from a user input, thus the while-loop will start regardless if its a 1 or 0
- Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.Using recursion, this code can now work in all versions of python 3, while it isn't a major improvement in bytes count, I'd still count making the code work in more versions an improvement! - Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!
Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!
I am not sure if this can be shortened, I have tried using a lambda, which is where I learned you can't merge a lambda and a while loophard to get lambdas to work, but every attempt ended up with more lines due to having to use recursion, if anyone has any ideas I think there is a byte or two theream all ears! Meanwhile I will try to keep pushing this, the new version feels like it has more that can be shanked.pushed