156k views
5 votes
Define a function named swap_nums that has 2 parameters: num_one and num_two. The function should swap the two numbers by using only one additional variable!

User Morris S
by
7.0k points

1 Answer

3 votes

Answer:

def swap_nums(num_one, num_two):

temp_value = num_one

num_one = num_two

num_two = temp_value

return num_one, num_two

print(swap_nums(10, 20))

Step-by-step explanation:

Create a function called swap_nums that takes num_one and num_two as parameters.

Inside the function, create a temporary variable, temp_value, and set it to the num_one. Set the num_one as num_two and num_two as temp_value. Return the num_one and num_two

Call the function with two numbers and print the result

User Ashlin Karkada
by
7.1k points