![]() What the function actually does is the work of this class. What this function does is make your class indexable, just like a list or dictionary. If you aren’t then I hugely recommend this guide, it has helped me enormously. The function _getitem_() is more mysterious if you are not familiar with pythons magic methods. This is fairly straight forward and as it says in the doc string if you give it a dictionary with mapping = Fizz, mapping = Buzz it will be FizzBuzz. The constructor takes a dictionary which maps numbers to what to print instead of their multiples. Mapping should be a dictionary with numbers as keys and what to print Here is a fairly simple class calledĪdvancedFizzBuzz which will give us a fully extensible FizzBuzz machine. ![]() I feel a more generic approach is needed here. If it's divisible by both 3 and 7, BuzzPop if it's divisible by 5 and 7 andįizzBuzzPop if it's divisible by 3, 5 and 7.Īnd of course if you say that multiples of 11 become Bizz you get into real trouble. If it's divisible by 7, FizzBuzz if it's divisible by both 3 and 5, FizzPop The number, Fizz if it is divisible by 3, Buzz if it is divisible by 5, Pop # = def fizz_buzz_pop(limit) :įor the each number in 1 - limit inclusivly, this function prints either
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |