Python Forum

Full Version: a coding challenge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
this is my coding challenge for July 2019. it qualifies to work if it runs correctly on at least one of the following versions of Python: 2.6.x, 2.7.x, 3.4.x, 3.5.x, 3.6.x, 3.7.x

code the smallest possible script that prints an exact copy of its own source code without reading any files.
Got it:

I could only get my version down to two lines which is twice the size of ichabod801's
 
 
SyntaxError: invalid syntax
Output:
SyntaxError: invalid syntax
  File "foo.py", line 1
    File "foo.py", line 1
    ^
IndentationError: unexpected indent
I tested mine in 2.7 and it worked.
i'm sure many of them work. i was trying to make a larger file. i osed the method of replacing the code with the output after it was run and did that a few times, checking that it wasn't alternating (a outputs b, b outputs a) and was the same each cycle. i posted what it converged to. i could change the file name in it.
a more difficult problem: your code should output "BREAKING NEWS! WORLD ENDS!" at the end of the source it outputs.