- Swapping 2 Numbers with third variable
num1 = 100
num2 = 200
print("num1 before swapping",num1)
print("num2 before swapping",num2)
temp=num1
#num1 value assinged to temp
num1=num2
#num2 value assigned to num1
num2=temp
#temp value assigned to num2
print()
print("num1 after swapping",num1)
print("num2 after swapping",num2)
Output will be
2. Swapping without using 3rd variable
num1 = 10
num2 = 20
print("num1 before swapping",num1)
print("num2 before swapping",num2)
num1, num2 = num2, num1
print()
print("num1 after swapping",num1)
print("num2 after swapping",num2)
Output will be
3.Check Number is Prime or not