Python Program to swap two variables
Aim: Implement
a program to swap two variables provided by the user.
Algorithm
1: Start
2: read 'a' and 'b' value
3: inter change the values
4.temp=a
5.a=b
6.b=temp
2: read 'a' and 'b' value
3: inter change the values
4.temp=a
5.a=b
6.b=temp
7. write a and b values.
8.stop
8.stop
Program:
x = input('Enter value
of x: ')
y = input('Enter value
of y: ')
# create a temporary
variable and swap the values
temp = x
x = y
y = temp
print 'The value of x
after swapping:”,x
print 'The value of y
after swapping: “,y
Enter value of x: 5
Enter value of y: 10
The value of x after swapping: 10
The value
of y after swapping: 5
0 Comments:
Post a Comment