Originally Posted by
Anakso
I need to write a program that reads in two variables (a and b) and swaps the values of the two variables. Each major function should be done in a separate function. So one function to get a value for a, one for b, one to swap their values and one to print them.
And yea, it's the last.
Asme's a = b, b = a doesn't work.
However temp = a, a = b, b = temp does work. That's called a three-way swap.
Code:
# fakultet
def swap(A, B):
temp = A
A = B
B = temp
return(A, B)
That's the Python version. (I know Python is a fucking joke when it comes to these small things with so few declarations. Script-language.)
>>>swap(4, 6)
(6, 4)