Course of Raku / Essentials / Associative data types / Exercises

Seen before?

Problem

Create a program that starts a loop with the following actions:

  1. Ask to enter a word.
  2. If the word has been seen once already, print Seen!.
  3. If the word has been seen more than once, print Seen 2 times!, etc.
  4. Repeat the loop.

Example

An example of interaction with the program:

$ raku seen-before.raku
Word: I
Word: never
Word: saw
Word: a
Word: saw
Seen!
Word: that
Word: saw
Seen 2 times!
True
Word: as
Word: that
Seen!
Word: saw
Seen 3 times!
True
Word: sawed
Word: ^C

To stop the program, press Ctrl+C.

Solution

See the solution

Next exercise

💪 Country codes

Course navigation

Positional data types / Subscripting ranges   |   Creating and calling functions

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська