BST Operations (BSTOPS) in Python 3: Wrong answer while submitting but everything fine with custom inputs

Hi I am new to both Python and CodeChef. I have written a Python 3 code for the 1st problem in the easy section and though it is working with different custom inputs I have tried with, it is giving “wrong answer” while submission. Can anyone please point me out what is wrong in my code. (In the meantime I am also looking for various seemingly tricky things in Python, like, accessing a global variable from inside a function and difference between “is” and “==” etc, which might help me debug my code)

My submission can be found here,
https://www.codechef.com/viewsolution/25389506

Thanks for your time. Really appreciate your help :slight_smile: