CHFING Python Syntax problem Help

I just want to know,
Why int(a/b) or math.floor(a/b) is not working instead of a//b in this question or in general? What are the cases where using first 2 methods will give different results than a//b?

My solutions links where i have used following methods to code :

  1. int(a/b) : CodeChef: Practical coding for everyone
  2. math.floor(a/b) : CodeChef: Practical coding for everyone
  3. a//b : CodeChef: Practical coding for everyone

Only 3rd one is AC.

I have read this stackoverflow post but it doesn’t explain case of both positive numers : python - Integer division: is a//b == int(a/b) true for all integers a,b? - Stack Overflow

int(a/b) first calculates a/b which is a floating point number in python3.6 ( and they have precision issues ) and then converts it into an integer. Similar thing with math.floor(a/b).
1 2 more in depth

1 Like

You lost some precision, when you convert float into int.

1 Like