-6

My friend gave me a challenge where the code is the same as the one in the output in python 3

I tried something like this :

input("")

Then you would type

input("")

into the shell.... but I assume the question is asking for it without user interactions. Thanks

ChewyCarrot
  • 222
  • 2
  • 12
  • 1
    This is a really vague and unhelpful question, can you provide some more details or an example. Is the challenge to have the code print a string of the source code to the console? – James Lingham May 17 '18 at 18:31
  • 1
    I think you're describing a [*quine*](https://en.wikipedia.org/wiki/Quine_(computing)), which should help you find examples yourself. – jonrsharpe May 17 '18 at 18:33
  • 1
    Possible duplicate of [shortest python quine?](https://stackoverflow.com/questions/6223285/shortest-python-quine) – Olivier Melançon May 17 '18 at 18:40

2 Answers2

1

I suspect what you are talking about is a quine.

a Simple quine in python would be

s = r"print 's = r\"{0}\"'.format(s), '\n', s" 
print 's = r\"{0}\"'.format(s), '\n', s
Snark
  • 1,664
  • 14
  • 27
0

What you are looking for is called a quine.

In essence, a quine is a program which prints its own source code.

See this answer for some examples.

Ziyad Edher
  • 2,150
  • 18
  • 31