Computer Science, asked by yojoshiv, 1 day ago

Write a program in Python to swap two numbers.

Answers

Answered by Ronithreddy
1

a = 10

b = 20

 

print("before swapping\na=", a, " b=", b)

 

temp = a

a = b

b = temp print("\nafter swapping\na=", a, " b=", b)

Answered by MichMich0945
0

Program:

# Python program to swap two number without

# a third variable

a = 70

b = 999

print("Before swapping", a, b)

a += b # a is now 1069

b = a - b # b is now 70

a -= b # a is now 999

print("After swapping", a, b)

Output is provided in the attachments...

Hope this helps you!

Attachments:
Similar questions