 # Difference between same syntax

Can somebody please tell me the difference between int((a-1)/2) and a//2.
I am getting a wrong answer if I use the first one and a correct answer when I use the second one.
But I think both of them are same

what if a=2 ?
not only 2 , for every even `a` both of these have different result.

let a = 10;
int( 9 / 2 ) = int( 4.5 ) = 4;
10 // 2 = 5;

i am taking only about odd values of a because in my code this statement is only executed if a%2!=0

Is a//2 is typing error?
Also try to give problem link or description. It makes easy to figure out the problem.

There is already a lot of discussion have done on the same topic in previous threads.
The Answer is, when your number increases to really a very large no, if you’ll do float division, it gives precision error because of memory buffer overflow, because when you do float division, memory also needs to store floating points. There is no such error occurs in integer division.

But then isn’t first one should give the correct answer since (a - 1) would be even and then there is no floating point division.
Where as in second case there will always be floating point division.

Converting int() too gives precision error, these are error at system level ,so one should always avoid it!

But if system is converting in int or not it depends on the type of variable declared, So assuming that a/2 gives correct answer it mean’s it should be integer data type or if it is float then the reason why first one is not giving the correct answer is typecasting to int.
I think the person who is asking the question should give more insight of his to come to any conclusion, also the problem detail.

Dear, Actually he is talking about python code, No variable declaration is required there. I think you get confused,bcoz of language!!

1 Like

yeah i assume it’s c++. Srry about that

In python // is integer division.

it would be better if you provide question link.