Chinese, asked by Anonymous, 1 month ago

Write a python program to swap two numbers.



Answers

Answered by Anonymous
140

INPUT-

# Python program to swap two numbers

num1 = input('Enter First Number: ')

num2 = input('Enter Second Number: ')

print("Value of num1 before swapping: ", num1)

print("Value of num2 before swapping: ", num2)

# swapping two numbers using temporary variable

temp = num1

num1 = num2

num2 = temp

print("Value of num1 after swapping: ", num1)

print("Value of num2 after swapping: ", num2)

OUTPUT-

Enter First Number: 101

Enter Second Number: 99

Value of num1 before swapping: 101

Value of num2 before swapping: 99

Value of num1 after swapping: 99

Value of num2 after swapping: 101

Answered by dipakmandaltutu1973
2

Answer:

See this example:

# Python swap 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: {}'. format(x))

Explanation:

Similar questions