Abish Pius

In this exercise, you’ll implement a somewhat complex (and whimsical) function, in a module, to implement tax policy in the Republic of Freedonia. The idea is that the tax system is so complex that the government will supply businesses with a Python module implementing the calculations for them.

Sales tax on purchases in Freedonia depends on where the purchase was made, as well as the time of the purchase. Freedonia has four provinces, each of which charges its own percentage of tax:

  • Chico: 50%
  • Groucho: 70%
  • Harpo: 50%
  • Zeppo: 40%

TRY IT YOURSELF

ANSWER

https://colab.research.google.com/drive/1GpnAi4qf3-4MwcQLDf3l0XkEhkdnSx3A?usp=sharing

--

--

In this exercise, you’ll write two functions:

  • gematria_for, which takes a single word (string) as an argument and returns the gematria score for that word
  • gematria_equal_words, which takes a single word and returns a list of those dict words whose gematria scores match the current word’s score.

For example, if the function is called with the word cat, with a gematria value of 24 (3 + 1 + 20), then the function will return a list of strings, all of whose gematria values are also 24. (This will be a long list!) Any nonlowercase characters in the user’s input should count 0 toward our final score for the word. Your source for the dict words will be the Unix file you used earlier in this chapter, which you can load into a list comprehension.

TRY IT YOURSELF

ANSWER

https://colab.research.google.com/drive/1Q1mSrNqWv3emIuKJGaNZRqdjhzjCvm1L?usp=sharing

--

--

Abish Pius

Abish Pius

Data Science Professional who teaches with unflashy, simple to understand python code.

Following