Repeated subtraction among two numbers | Python3 program to count of steps until one of the two numbers become 0. ; Returns count of steps before one of the numbers become 0 after repeated subtractions . ; If y divides x , then simply return x / y . ; Else recur . Note that this function works even if x is smaller than y because in that case first recursive call exchanges roles of x and y . ; Driver code
import math NEW_LINE def countSteps ( x , y ) : NEW_LINE INDENT if ( x % y == 0 ) : NEW_LINE INDENT return math . floor ( x / y ) ; NEW_LINE DEDENT return math . floor ( ( x / y ) + countSteps ( y , x % y ) ) ; NEW_LINE DEDENT x = 100 ; NEW_LINE y = 19 ; NEW_LINE print ( countSteps ( x , y ) ) ; NEW_LINE