You are not logged in. Please login at CSPathshala to post your questions!

×

Error During Submission of Life, the Universe, and Everything

I submitted a solution for the problem "Life, the Universe, and Everything", based on the sample input and output. I got a Run time Error (NZEC). I googled the cause of this error and got to know that online platforms expect input delimited by space. So I changed the code and resubmitted and I got "Wrong Answer". I know my both my solutions work but do not know what CodeChef Expects. Please help.

Solution 1: (this gave runtime error, input is as per sample input one below the other)


num=[]
while 1:
  n = input()
  if (n == ""):
    break
  n=int(n)
  num.append(n)

for numbers in num: if (numbers == 42): break print(numbers)

Solution 2: (This gave wrong Answer, input is on one line delimited by space)


a=[int(x) for x in input().split()]

for numbers in a: if (numbers == 42): break print(numbers)

asked 26 Jul '18, 09:46

Priyashriram's gravatar image

0★Priyashriram
1111
accept rate: 0%


Hello ma'am, You need to take input assuming that the input will come in the format given in sample input. Here it is 1 integer input in each line as mentioned in the question here: www.codechef.com/TTPUNE/problems/TEST/

Kindly try and modify your program accordingly.

link

answered 26 Jul '18, 12:56

pallavi's gravatar image

0★pallavi
1233
accept rate: 0%

The "Solution 1" was accepting input as per sample. But that gave runtime error NZEC hence I modified the code.

The issue is that the question does not specify when to stop the input. I assumed a NULL (i.e. ENTER without value) means the input has stopped and the output should start.

(27 Jul '18, 10:59) Priyashriram0★

I submitted this solution and CODECHEF accepted it, even though it does not satisfy the input and output requirements.


while(True):
    x = int(input())
    if x == 42:
        break
    else :
        print (x)
(27 Jul '18, 11:21) Priyashriram0★

The problem says that keep accepting input and print it till the user enters 42.

The above program is satisfying the given requirements and so it worked.

(27 Jul '18, 18:55) pallavi0★

But it does not match sample input and sample output!!!

(28 Jul '18, 10:16) Priyashriram0★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Tags:

Asked: 26 Jul '18, 09:46

Seen: 1,431 times

Last updated: 28 Jul '18, 10:16

Related questions