0

I used the Search Function to no avail on this. Let us say I want to write a function which echoes out what we input, like so:

def echo (p): 
   return p

But what if we wanted to enter an input that took more than one line? For example:

INPUT

2
0
1
3

OUTPUT 

2
0
1
3

I could just use something outside of a function as shown here, but what if I wanted to use it as a function?

Thanks in advance!

Community
  • 1
  • 1
Ahaan S. Rungta
  • 2,323
  • 2
  • 12
  • 15
  • Please re-read my post. I already mentioned that I have seen that thread. My question is about how to put it in the form of a function. – Ahaan S. Rungta Nov 18 '13 at 20:56
  • So? What's the problem then? You're simply gonna call `echo('2\n0\n1\n3')` Please specify what you want exactly, because this question doesn't seem to make much sense. – wvdz Nov 18 '13 at 20:56
  • @popovitsj Try putting what you mentioned in IDLE. It prints `2\n0\n1\n3` rather than 2, 0, 1, and 3 separated in different lines. – Ahaan S. Rungta Nov 18 '13 at 20:58
  • See my comment on Truerror's post. I figured it out. – Ahaan S. Rungta Nov 18 '13 at 20:59

1 Answers1

1

Is that input a string?

If yes, then you could put your string in a variable (you can do multiple line string in a variable with ''' and end with ''') and use that variable as the argument for your function.

Ahaan S. Rungta
  • 2,323
  • 2
  • 12
  • 15
Truerror
  • 146
  • 4
  • Oh, whoops, I see to have figured it out. What I want is a `print` statement. Thank you so much! – Ahaan S. Rungta Nov 18 '13 at 20:58
  • Lol you serious? You skipped lesson one "Hello World"? – wvdz Nov 18 '13 at 21:00
  • how one gets to functions without print is beyond me – crownedzero Nov 18 '13 at 21:01
  • Wait, actually, the issue is not resolved. I know what `print` statements are, I've been programming for the last 2 years. :P The problem is, I have to input it with `\n` characters, which is what I've trying to avoid. – Ahaan S. Rungta Nov 18 '13 at 21:02
  • @popovitsj Ah yes, the old 'Hello World'. I must inform you that the new, hip way of starting to code is 'Boom Boom Pow', not that antiquated 'Hello World'! What? It's Black-Eyed Peas! It's hip, I tell you! – Truerror Nov 18 '13 at 21:08
  • @Truerror Wow, really? I'm still learning programming languages and I've never seen something other than `Hello World!` - that's funny! – Ahaan S. Rungta Nov 18 '13 at 21:16
  • So what you're saying is, I want to give newlines as input without using the newline character? (Ps lol @Truerror) – wvdz Nov 18 '13 at 21:32
  • @popovitsj That, or he simply doesn't want to write an actual newline character, thus my answer above. Depending on his reply, this could be a wild goose chase. Meanwhile, I'm off to TheDailyWTF :) – Truerror Nov 18 '13 at 21:53
  • It seems I have figured out enough for the purposes of the problem I am trying to write; I'm just using a file and importing it with Python. Thanks, everyone! – Ahaan S. Rungta Nov 18 '13 at 22:27