Login and get codingRefactor the code from
invoice_to_be_refactored
insideinvoice_refactored
and 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_movies
raise a LookupError
- For the matching movie get thediscount
andprice
:
-discount
=10
if you buy5
or more tickets
- price =12
if the quality isIMAX
else10
- Calculate and return theprice
=tickets * price - discount
Note: 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! 😌