Q:

Python program for swapping the value of two integers

belongs to collection: Python basic programs

0

The basic idea is:

  • Storing the value of one variable (x) in a different variable (namely temporary - temp).
  • Then changing the value of x by copying the value of y.
  • Then changing the value of y by copying the value of temp.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

So here is the code:

x = float(input('ENTER THE VALUE OF X: '))
y = float(input('ENTER THE VALUE OF Y: '))

temp = x
x = y
y = temp

print('X :', x,' Y :', y)

Output:

ENTER THE VALUE OF X: 10
ENTER THE VALUE OF Y: 20
X : 20.0  Y : 10.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for swapping the value of two integ... >>
<< Python program to count number of trailing zeros i...