Why this reverse string logic in java wont work in python? -
please explain why logic wont work in python. works in java?
def reverse(number): reversednumber = 0; temp = 0; while(number > 0): #use modulus operator strip off last digit temp = number%10; print(temp) #4 #create reversed number reversednumber = reversednumber * 10 + temp; number = number/10; print("reversednumber", reversednumber)
reverse(1234)
in python 3 dividing 2 integers can return float. in languages 1/2 == 0
. in python 3 1/2 == 0.5
. integer division in python 3 use double division sign, i.e. 1//2 == 0
.
note, difference between python 2 , 3.
also not work because comments in python written starting #
not //
.
Comments
Post a Comment