# Solved Homework: Question: This assignment is to provide you with practice using loops. Thus loops should be used wherever a…

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…

```import random

def dice_roll(retain, dices):
for i in range(5):
dice=random.randint(1,10)
if dices[i]==retain:
continue
else:
dices[i]=dice
return dices

def play():
print("Hi, welcome to Yat!")
dices=[None]*5
dices=dice_roll(0, dices)
for i in range(5):
num=dices[0]
if dices.count(num)==5:
choice=("You WIN! Would you like to play again? Please enter Y (yes) or N (no) ")
if choice.lower()=="n":
return
elif choice.lower()=="y":
dices=dice_roll(0, dices)
i=0
continue
elif (not i==4):
value=int(input("your "+str(i+1)+" roll is: "+str(dices)+" which value you would like to keep?"))
dices=dice_roll(value, dices)
if i==4:
choice = input("You LOST! Would you like to play again? Please enter Y (yes) or N (no) ")
if choice.lower() == "n":
return
elif choice.lower() == "y":
dices = dice_roll(0, dices)
i = 0
return 4
def main():
i=play()
while i==4:
i=play()

main()```

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.