-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswapTwoVariables.py
More file actions
27 lines (18 loc) · 906 Bytes
/
swapTwoVariables.py
File metadata and controls
27 lines (18 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#Swaping the variables using temp method
firstVar = input("Enter the first variable here: ")
secondVar = input("Enter the second variable here: ")
print("The first variable before the swap is: ", firstVar)
print("The second variable before the swap is: ", secondVar)
temp = firstVar
firstVar = secondVar
secondVar = temp
print("The first variable after the swap is: ", firstVar)
print("The second variable after the swap is: ", secondVar)
#Swapping the variables using left, right method
newFirstVar = input("Enter a new first variable: ")
newSecondVar = input("Enter a new second variable: ")
print("The first variable before the swap is: ", newFirstVar)
print("The second variable before the swap is: ", newSecondVar)
newFirstVar, newSecondVar = newSecondVar, newFirstVar
print("The first variable after the swap is: ", newFirstVar)
print("The second variable after the swap is: ", newSecondVar)