Assignment 2: Problem Solving Example

Unit 0 > Assignment 2 > problem solving


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:

 

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:

 

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
  
 

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.


© 2020, Rahul Simha