Apr-17-2020, 09:24 PM
Hi,
For a choice of 4 letters (a, b, c, d) for example, a sequence of letters is displayed, arranged as follows:
I like this approach but I can't quite grasp the use of the min () function, the mechanism escapes me completely in this program.
Could someone please explain to me how the min() function works in this case?
For a choice of 4 letters (a, b, c, d) for example, a sequence of letters is displayed, arranged as follows:
Output:aaaaaaa
abbbbba
abcccba
abcdcba
abcccba
abbbbba
aaaaaaa
with this code:1 2 3 4 5 6 7 8 9 10 11 12 |
alphabet = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ] choice = int ( input ()) size = choice * 2 - 1 line = 0 for _ in range (size): column = 0 for _ in range (size): print (alphabet[ min ( min (line, size - 1 - line), min (column, size - 1 - column))], end = '') column + = 1 line + = 1 |
Could someone please explain to me how the min() function works in this case?