petoor's blog

By petoor, history, 3 months ago, In English,

Hey guys.

I am new to submitting in python, my code is as follows:

n = int(input()) k = int(input())

if(divmod(n,2)[1]==0): stop_odd = n/2 else: stop_odd= n/2+1 if(k<stop_odd): answer = k*2-1 else: k = k-stop_odd answer = k*2 if(k==0): answer=n-1

print(int(answer))

It is for the problem 318A — Even Odds.

Can anyone tell me why i see the exit code, as the code seems to compile and run in my own editor.

Thanks.

 
 
 
 

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

can you send submission link?

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

int(input()) reads a line but in problem n and k are inputted in one line. So, write n,k = input().split(' ')) . Click.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks.

    Is there any reason why it has to be inputted in one line in python, and in Java the input can be inputted after a new line.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Further question. Is there any information about which packages i can import? This code is unnecessary bad due to a lack of ceil and floor functions. Can i load python math?

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Sorry, I don't know python good, I just know very basics of it.

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You should be able to import all libraries that come with a default installation of Python. Like math, fractions, ...

      Libraries that you have to install afterwards (e.g. with pip) will not work.