I'm a newbie and this is my first stupid question on StackOverflow. Would anybody let me know why line 7 was executed while the condition is false (input = 1
)? This is the screenshot
Thanks a lot and all the best to you!
print("line 1 - START OF CODE - right before function 'def decimalToBinary(num)' \n", "line 2-9 - define function 'decimalToBinary(num)'")
def decimalToBinary(num):
print("\n Line 2 - execute the function 'decimalToBinay(num)'' \n Line 3 - right before if statement - at this line num value is:", num, ", var number is:",number,"\n")
if num > 1:
print("Line 4-5 - 'if statement' is true (num > 1), num value is", num, "> 1", "\n Line 6 - recall function 'decimalToBinary(num // 2)' \n")
decimalToBinary(num // 2)
print("Line 7 - 'if statement' end - This is num after line 6 'decimalToBinary(num // 2)'. Num is",num)
print("Line 8 - This is num before the line 'print(num % 2)':", num)
print("Line 9 - This is result of num % 2:", num % 2, "\n")
number = int(input("line 10 - Ask user 'Enter any decimal number:' then assign this value to var 'number' \n line 11 - call function 'decimalToBinary(number)': "))
decimalToBinary(number) #function call
print("line 12 - END OF CODE")