Login and get codingRefactor the code from
invoice_to_be_refactoredinsideinvoice_refactoredand make it more readable. Currently the function exhibits the infamous Arrow anti pattern.Remember from the Zen of Python: flat is better than nested, so try to flatten it with the following techniques:
To summarize the code:
- If 0 tickets raise a
ValueError
- If the movie passed into the function does not match any movies inavailable_moviesraise a LookupError
- For the matching movie get thediscountandprice:
-discount=10if you buy5or more tickets
- price =12if the quality isIMAXelse10
- Calculate and return theprice=tickets * price - discountNote: there is no single correct solution for this exercise. The goal is to get more familiar with refactoring techniques.
This exercise was inspired by Martin Fowler's Refactoring book.
22 out of 24 users completed this Bite.
Will you be the 23rd person to crack this Bite?
Resolution time: ~23 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 2.0 on a 1-10 difficulty scale.
» You can do it! 😌