The print here is optional, but it’s nice for the player to be able to immediately see what they rolled. The function needs to do two things: create the list and then return it. I check my code in two different ways: Visually, using print: dices = Roll() print (f'is it Yatzy? ! \n') return self._current_dice_list If you wait until it is all done it can be really painful to fix errors. Congratulations! Check your codeĭon’t forget to check your code as you write it. If the length of that set is one - you have Yahtzee. That’s it! In a set, you can’t have any equal items - so, if they’re all the same, you end up with just a single item. Take a look: def check_yatzy(self, dice_list): if len(set(dice_list)) = 1: return True return False ![]() You could - but using sets is so much easier. If you’re not familiar with sets, you may be thinking you could simply loop through the list and check if the next item is the same as the last one. ![]() We pass a list as an argument and we know that all the items on that list will have exactly the same value.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |