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…

Expert Answer

import random

def dice_roll(retain, dices):
    for i in range(5):
        if dices[i]==retain:
    return dices

def play():
    print("Hi, welcome to Yat!")
    dices=dice_roll(0, dices)
    for i in range(5):
        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":
            elif choice.lower()=="y":
                dices=dice_roll(0, dices)
        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":
            elif choice.lower() == "y":
                dices = dice_roll(0, dices)
                i = 0
                return 4
def main():
    while i==4:


Vidyalai [CAUsers Nasir Bhat PycharmProjects [Vidyalai] - PyCharm Eile Edit iew Navigate Code Refactor Run Iools VC Window Help qradle Visual Studio I iausStat.ру Code return4 python_co... Advanced 38 def main () 39 i-playO while i-4 main while i-4 DiceRoll Run: DiceRoll DiceRoll DiceRoll DiceRoll DiceRoll EWallet Android Studio C:UsersNasir Hi, welcome to Tat! your 1 roll is: [4, 3, 2, 3, hich value you would 1ike to keep23 your 2 roll 13: [2, 3, 7, 3, 61 hich value you would 11ke to keep?3 your 3 roll is: [8, 3, 7, 3, 7] which value you ould like to keep?3 ↑ BhatPycharmProjectsWidya 1anvenv Scriptapython.exe C:/Users/tlasir Bhat/PycharmProjects/Vidyalai/DiceRoll.ру MRI HEAD.Recycle Bin your o : [6, 3, 7, 3, 101 vhich value you would like to keep?3 <no) 2)zip You LOST! Would you like to play again? Please enter Y (yes) or H1, we1come to Yat! your I roll 23: [8, 8, 6, 2, 6] which value you would like to keep? 8 your 2 roll is: I, 8, 1, 1, 4] which value you would like to keep?e your 3 roll is: , 8, 4, 9, 3] which value you would 1ike to keepz8 your roll 13: 8, 8, 10, 7, 11 wilch value you would 1ike to keeps You LOST ! ould you like to play again? Please enter Y 《yes) or N (no) n y 血 MRI HEAD..VLG media Process inished with exit code 0 Chrom IDE and Plugin Updates PyCharm is ready to update. Nasir progr IDE and Plugin Updates: PyCharm is ready to update. (40 minutes ago) 11:34 PM U: 0.21 KiB/s 11/10/2018 4

Buy Essay
Calculate your paper price
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.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

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

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

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.


Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?