With a challenging problem, what is often hardest is getting started. Where to begin?
Let's start by examining the output more closely:
At this point, it's important NOT to think about coding details. This is a critically useful strategy that deserves some explanation:
So now, let's just think high level but a little code-like:
for i going from 1 to 10 figure out and print the i-th line
Next, if we could somehow figure out the last letter in each line, we'd be in good shape, because:
for i going from 1 to 10 figure out the last letter in line i print from z down to that last letter
We need to figure out the last letter in the i-th line:
k = ord('a') # k will turn out to have 97
letter = chr(97) # letter will turn out to have 'a'
k = chr('z')
k = chr('z') j = k - i # i spots behind (or less)
k = chr('z') j = k - i letter = chr(j) # the letter i spots behind
Let's summarize what we have so far in pseudocode:
for i going from 1 to 10 k = chr('z') # the number of the letter i spots behind j = k - i Now print all the letters corresponding to the numbers from k to j
for i going from 1 to 10 k = chr('z') # the number of the letter i spots behind j = k - i for n starting at k and going down to j get the letter corresponding to n and print it
for i in range(1, 10): k = chr('z') j = k - i for n in range(k, j, -1): c = chr(n) print(c)
A2.1 Exercise: Write up the above in my_char_problem.py. What do you notice?
A2.2 Exercise:
We deliberately left in two unaddressed problems above.
Fix the problems in
my_char_problem2.py.