python 3.x - Number sort using Min, Max and Variables -
i new programming , trying create program take 3 random numbers x y , z , sort them ascending order x being lowest , z highest using min, max functions , variable (tmp)
i know there particular strategy need use effects (x,y) pair first (y,z) (x,y) again can't grasp logic.
the closest have got far is...
y=min(y,z) x=min(x,y) tmp=max(y,z) z=tmp tmp=max(x,y) y=tmp x=min(x,y) tmp=max(x,y) y=tmp
i've tried many different combinations seems problem unsolvable can else help?
you need sort x,y pair first
tmp=min(x,y) y=max(x,y) x=tmp
then sort y,z pair
tmp = min(y,z) z=max(y,z) y=tmp
then, resort x,y pair (in case original z lowest value...
tmp=min(x,y) y=max(x,y) x=tmp
if commands have mentioned ones available on website, , can use each 1 once try:
# sort x,y pair tmp=max(x,y) x=min(x,y) y=tmp # sort y,z pair tmp=max(y,z) y=min(y,z) z=tmp # sort x,y pair again. tmp=max(x,y) x=min(x,y) y=tmp
hope helps.
Comments
Post a Comment