Suggest adding hint to first task of new Plane Ticket exercise

I wrestled a bit with the first task. I think in general that’s great (i.e. desirable difficulty), however I wanted to walk you through my thought process in case there’s an improvement to be had.

  • At first I assumed that a generator would always be infinite (even though the introduction clearly has examples that aren’t infinite)
  • I couldn’t figure out if the generator was meant to return just one letter at a time, or number letters at a time.
  • I completely blanked on the fact that I could use % to get an index to get the right letter, and ended up googling around a bit.

Would it make sense to add a sentence to the instructions? Something like:

The generator should return a single letter each time next() is called. The generator will stop returning letters after next() has been called number times.

(I don’t know if the above is correct, so this is just a suggestion to get the conversation started).

In order to discretely point towards the % trick, maybe one of the examples in the introduction could talk about using a clock? Not sure if it’s subtle enough. Or maybe add something to the hints?

Hi @MangoSeed :wave: :smile:

Thank you so much for your feedback! I was a bit worried about releasing this exercise - its a bit of a leap from the others in the syllabus, and could benefit from multiple prerequisite exercises (like iterators and comprehensions and itertools and more) that we haven’t (yet) gotten launched.

But its been on ice for waaaay to long, so we decided to publish and then fill in the prerequisites later. :sweat_smile:

We definitely should make that clearer. We do talk about a generator being consumed, but we could probably make that more prominent. Maybe we add some more detail to, and maybe even re-arrange it a bit? Very open to suggestions on that.

Yeah - I definitely see where that could be ambiguous. Here is one thought/suggestion, but I am very open to others, This one might be too “heavy”:

## 1. Generate seat letters

Conda wants to generate seat letters for their airplanes.
An airplane is made of rows of seats.
Each row has _4 seats_.
The seats in each row are always named `A`, `B`, `C`, and `D`.
The first seat in the row is `A`, the second seat in the row is `B`, and so on.
After reaching `D`,  the naming should start again with `A`.

Implement a function `generate_seat_letters(<number>)` that accepts an `int` representing how many rows of seat letters need to be generated.
The function should return a generator-iterator that will yield seat letters one at a time.  

In other words, your function should yield a single letter each time `next()` is called, until there are no more values to return.

>>> letters = generate_seat_letters(5)
>>> next(letters)
>>> next(letters)
>>> next(letters)
>>> next(letters)
>>> next(letters)
>>> next(letters)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

Maybe we could add some lines to here about modulus, linking back to the numbers concept? And we could also write out some examples of what x % 4 returns?

Maybe we also mention that sequence types (list, str, tuple) all have common sequence operations that include using bracket notation (and that as long as what is in the brackets resolves to a valid index, you can do as much math as you like!)?

Finally, after reviewing some of the submitted community solutions, I think we might also want to link to itertools.cycle - especially since the equivalence example code has a really nice generator example, even though itertools.cycle by itself actually returns a cycle object as opposed to a generator.

I am intrigued :smile: - do you have a thought on what the clock-like example would look like in the I’d love to include more examples in the docs!

I really like that. It doesn’t feel heavy. It illustrates the wrapping from 'D' to 'A', as well as the StopIteration, as well as the one letter at a time.

For my sake writing out examples of % would be overkill. I had a very foreheadslap moment when I realized that I should have been thinking in the direction of %. That said, I’ve been programming for a couple of decades, and for people who are newer some examples might be just what the doctor ordered.

I really like this as a hint, actually. That points people in the direction of thinking about the index of the sequence (I was thinking in terms of iterating over it, so I basically got myself stuck in a rut there), as well as the idea that you could manipulate something to get a good index.

Yeah, thinking about this more I really like that. It feels more like a hint, whereas explicitly talking about % would be giving it away.

Maybe it’s worth giving it a try, and if people get stuck a lot we could add a more explicit hint?

Ok, totally just making this up. How about an AI bot that posts a serial story in n installments? It posts a new installment every 7 hours.

func generate_publication_times(number):
    hours = list(range(24))
    for n in range(n):
        yield hours[n % 7]

It has the same shape as the first task, though, so it might give too much away.