I am practicing simple Python algorithms and I was a little confused by the correct result of one. A particular part of the algorithm in particular wherein two strings of equal length must be greater than the other for the algorithm to function; yet, on the surface the seem equal size-wise.
My assumption is the greater than status of one string over another on is determined by comparing the ASCII value of individual elements of the different strings to each other. If one ASCII value is higher than another one at one particular index than THAT string is greater than the other one.
The goal is to create a new string made of the first char of s1, then the last char of s2, Next, the second char of s1 and second last char of s2, and so on. Any leftover characters go at the end of the result.
The correct result being: “AzbycX”
Actually, I just realized that A would have a lower ASCII scored than z. So I’m really lost about why these two values would be greater than one another. Somehow they are because the code functions when I run it in VSCode. Now I wonder if it’s the combined ASCII scores of each…? I don´t know. I would like some help on clarifying this though.
str1_length > str2_length evaluates to False, as 3 is not greater than 3. Due to that biggest = str1_length is not executed, but as there’s else the code from it is executed - biggest = str2_length.
To summary - the code here doesn’t necessarily answer which one is bigger. It defines what to do when str1_length is bigger than str2_length. And what to do when that’s not a case - then str2_length is either bigger or equal to the str1_length.
Of course. I was getting sidetracked on the idea of comparing them that I never considered that if both variables are equal it is a moot point and it will logically continue to the next consideration. Thank you.