3 ms·
Nitpick: you could replace sys.stdout.write(f"{n}\n") with print(n). The current code looks very much like it was written for Python 2 (apart from the f string!
by quietbritishjim 2y ago
Nitpick: you could replace sys.stdout.write(f"{n}\n") with print(n). The current code looks very much like it was written for Python 2 (apart from the f string!), where print was a statement. As of Python 3, print is just a regular function. It returns None, which is falsey, so you'd also need to change your first "and" to an "or".
- jftuga 2y agoThanks for this suggestion - it works great. import sys # run: python3 countdown.py 10 def main(n:int): print(n) or n-1 and main(n-1) main(int(sys.argv[1])) This also works and is definitely more Pythonic: _ = [print(n) for n in range(10,0,-1)]