Exercise 1

Write an algorithm in python which exchanges two integers m and n entered on the keyboard and which displays the values of the numbers before and after the exchange operation.

Solution


# Ask user to type values of n and m
n = int(input("Type value of the integer n : "))
m = int(input("Type value of the integer m : "))

# use an auxiliary variable in order to be able to exchange the values of m and n
print("display m and n before exchange values : " , " n = ", n , "m = ", m)
v = 0
v = n
n = m
m = v
print("display m and n after exchange values : " , " n = ", n , "m = ", m)

Younes Derfoufi
my-courses.net

Leave a Reply