Find us on Facebook

Thursday, December 13, 2018

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
7. write a and b values.
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
Output:
 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:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates