Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this problem, you will begin creating a program that will allow a person to

ID: 3814667 • Letter: F

Question

For this problem, you will begin creating a program that will allow a person to play Yahtzee. You will only do one small part of the program, however. Your job will be to: Use the random number generator, seeded with time, to assign 5 random numbers (1 -6) into an array Print the five dice numbers to the screen Ask the user to select which dice they'd like to keep Then roll the non-selected dice again Print the five dice numbers to the screen Again, ask the user to select which dice they'd like to keep Then take the final roll of the non-selected dice Print the final dice rolls to 3 2 5 1 5 the screen. Output should look like this: You should use an integer array for the dice and a character array for whether you keep the dice not. Everything can be done in main. Would you like to keep dice 1? N Would you like to keep dice 2? N Would you like to keep dice 3? Y Would you like to keep dice 4? N Would you like to keep dice 5? Y Would you like to keep dice 1? Y Would you like to keep dice 2? N Would you like to keep dice 3? Y Would you like to keep dice 4? N Would you like to keep dice 5? Y

Explanation / Answer

main.py

import random

class Dice():


   def dice(self, num):
       dice = []
       for i in range(num):
           dice.append(random.randint(1,6))
       return dice

   def first_roll(self):
       raw_input("Press ENTER to roll the dice...")
       roll1 = self.dice(5)
       return roll1

   def second_roll(self, roll1):
       print roll1
       print "Which dice would you like to keep? [0,4]"
       # creates a list by mapping input "x x x x x" as integers
       # to [x, x, x, x, x], and checks for input errors.
       while True:
           try:
               keep_index = raw_input("> ")
               keep_index = map(int, keep_index.split())
               break
           except ValueError:
               print "Please type your keepers in index form "x x x x x""

       keep_dice = []
       roll2 = self.dice(5 - len(keep_index))

       for i in keep_index:
           keep_dice.append(roll1[i])


       print "You kept dice: ", keep_dice
       raw_input(" Press ENTER to roll the other dice... ")
       print "You rolled: ", roll2
       keep_dice = keep_dice + roll2
       print " Your dice are: ", keep_dice
       return keep_dice

   def third_roll(self, roll2):
       print " Which dice would you like to keep? [0, 4]"
       while True:
           try:
               keep_index = raw_input("> ")
               keep_index = map(int, keep_index.split())
               break
           except ValueError:
               print "Please type your keepers in index form "x x x x x""

       keep_dice = []
       roll3 = self.dice(5 - len(keep_index))

       for i in keep_index:
           keep_dice.append(roll2[i])
       print "You kept dice: ", keep_dice
       raw_input(" Press ENTER to roll the other dice... ")
       keep_dice = keep_dice + roll3
       print " Your dice are: ", keep_dice
       return keep_dice

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote