Predict the output of the Python code given below:
for CNT in range (4,0,-1):
print(Diff(A,B),'#', end=' ')
Output: 22 # 40 # 9 # 13 #
- The function Diff( ) takes 2 numbers as parameters and finds the difference by subtracting the smaller number from the larger number and returns the difference.
- NUM is an array of 5 numbers.
- The for loop iterates from 4 to 0 by decrementing by 1.
- A and B are assigned 2 consecutive numbers from the array NUM and the difference is calculated and printed. This is repeated for all 2 consecutive numbers in the array.