What is the purpose of using w in lines 4 to 6 of the code?

Asked 1 years ago, Updated 1 years ago, 213 views

def median(x,y,z):
    print(x,y,z)
    if x>y:
       w = x
       x = y
       y=w
    print(x,y,z)
    if z<x:
         return x
    if z<y:
       return z
    returny
assert median(3,1,2) == 2

python

2023-02-13 13:35

1 Answers

 if x >y:
  w = x
  x = y
  y=w

This code replaces x and y when x is greater than y.(The first and second arguments of the function median are arranged in ascending order.)


2023-02-13 17:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.