0

I'm a beginner, and I'm training on CodeAbbey. They give you input, you can hardcode it but I'd rather like to use the input commands.

When it's a single line input it's pretty easy, I read it and store it in a list. This becomes tricky when they give multiple line inputs. At first I cheated a bit, I did copy/paste for each line one after the other. But sometimes there's 40 tests to do, so 40 copy/paste...and I'm lazy. So lazy I spent 2 hours searching how to get my multiple line input in a list.

It's a list of numbers, so basically this is what I do :

list1= [int(x) for x in input("your input").split()]

This works fine to store numbers in a list. But when I have multiple lines in my input, this gives me only the first line. I also tried :

list1= [int(x) for x in input("your input").split("\n")]

Or :

list1= [int(x) for x in input("your input").replace("\n", "")]

These change nothing, only got the first line of input.

I read that the simpler solution would be to store the input a text file and read it with my code, but I did not want to use external files right now as I'm starting to learn.

Thanks for your answers(and excuse my pretty bad english, not a native speaker).

EDIT : The exercise in question : http://www.codeabbey.com/index/task_view/min-of-three

I copy/paste the test data as my input as recommended, but only the first line is stored. I mean, if I print my list, only the first number is displayed, if I print the length of my list with len(), I get 0, which means I have 1 item in my list, right?

8
  • 1
    What indicator do you want that the lines are done? Commented Mar 8, 2016 at 12:52
  • Pro tip is to not use inline-code like you're doing if you're new to this. Split your code into blocks instead. Might make more sense even tho it doesn't solve your actual problem. Commented Mar 8, 2016 at 12:55
  • Can you link us to the problem on CodeAbbey? You might be going about this in the wrong way Commented Mar 8, 2016 at 12:57
  • Note that the linked duplicate refers to raw_input, but that function is the same as Python 3's input. Commented Mar 8, 2016 at 13:04
  • This is a bit opinionated, but programs that take user input are generally a bad idea. Among other things they are difficult to test and automate. My suggestion is that your starting point should almost always be to take inputs from command line options or from from text files. Commented Mar 8, 2016 at 13:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.