Does it matter how we take the input data ?

Back to General discussions forum

Arman Cam     2019-06-12 11:22:42
User avatar

In general, the problems have the input form of like this. First referring to the number of inputs and then the data itself. I always ignore the number of the data part Is this effects the correctness of the code or not?

In this type of problems my code is usually like this (using python)

file = open("text.txt","r")
for line in file:
    a,b,c = int(line.split(" ")[0]), ...
...

I always ignore the number of input. Is this can make a problem in the future when I wanted to get a certificate?

Rodion (admin)     2019-06-12 12:36:04
User avatar

Hello!

It doesn't matter :)

The amount of input data is given usually because in some languages it is easier detect the end of input and in some harder. So generally just your answer matters. As about certificates - it only matters that your solutions exist, are relevant to the task (i.e. not some random code) and are not copied from somewhere :)

I also may add that:

file = open("text.txt","r")

it usually makes sense to read input directly from console - in such case solution may be executed just from the site using buttons below solution form (and when running locally, data could be copy-pasted into console).

Though if you are convenient with reading from file (or storing input as a multiline string in the code itself) - it's ok!

Arman Cam     2019-06-12 12:50:22
User avatar

Oh, that's a relief. It's generally easier for me to use files but sometimes I just copy and paste the data to an array or run a test code as you referred

Thanks a lot! :)

Mihai Lazarescu     2022-07-19 17:44:22

Hello, can you tell me why in Python input().split() reads only the 1st line of the problem input? Thank you!

zelevin     2022-07-19 18:58:06

Mihai:

That's what input does: https://docs.python.org/3/library/functions.html#input

If you want to read more lines, you might want to loop.

Please login and solve 5 problems to be able to post at forum