This assignment is to provide you with practice using loops. Thus loops should be used wherever appropriate. Other methods of solving the problems will not receive full marks even though they may work. The use of the “break” keyword is not permitted in this assignment. Also, using loops such as “while True:” is bad practice. Reduced marks will be given for solutions that use such constructs.
Question 3: Yat (a much simplified version of Yahtzee)
You will roll 5 dice with the goal of getting 5 of a kind within 4 rolls. The resulting number on each die will be generated randomly. You can use the “random” module to generate a random number between 1 and 10. You can read about the random module in the Python documentation.
The way you will use it is something like random.randint(a, b).
The user will decide which of the values they want to keep out of the current roll.
For instance if the current roll is (2, 3, 2, 1, 6), the user may specify that they wish to keep the 2’s. In this case, in the dice that do not contain the value 2 will be rolled again. If the player does not have 5 of a kind after 4 rolls, inform them that they have lost the game and ask if they would like to play again.
If they have 5 of a kind, inform them that they have won the game.
Remember, the user may change their mind as to which values to keep so it shouldn’t be assumed that they are trying for the same value for all 4 rolls. At each roll, your program should show the current value of each die.
For instance, your program might look like this:
Hi, welcome to Yat!
Your first roll is: 5, 6, 1, 5, 5 Which value you would like to keep? 5
Your second roll is: 5, 5, 6, 5, 5 Which value would you like to keep? 5
Your third roll is: 5, 5, 5, 5, 5 You WIN! Would you like to play again? Please enter Y (yes) or N (no) etc…