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

Create the following graphics dice program. DiceHW5Example.png The user will be

ID: 3837693 • Letter: C

Question

Create the following graphics dice program. DiceHW5Example.png The user will be "throwing" 5 dice. They will "throw" each of the 5 dice by clicking on their respective outlined areas. You will then need to generatePreview the documentView in a new window a number between 1-6 for each click/throw and display that dice side in the clicked outlined area. After each click/throw the new running total will appear below the dice. After all the dice have been clicked/thrown you will display a message below the dice total remarking on how lucky they are. Have an Exit button the user can click to exit the program. You can assume that the dice are clicked/thrown in order of 1 to 5. This program does not allow a second click/throw on a dice. If the user clicks outside of the dice outlines nothing should happen, no dice display, no error message. You need to use a function that is called with every dice click/throw. You need to use a function that generates the random dice numberPreview the documentView in a new window between 1-6. This program draws that dice in the appropriate outlined area. You can do this by calling another function or functions. This is the pattern for each of the sides of the dice.

Explanation / Answer

def dice_graph():

#import random library

import random

# this generates a random integer between and including 1 and 6

intNum = random.randint(1, 6)

return intNum

def dot():

intNum = dice_graph()

if intNum == 1:

    #draw the main dot in the center of the die

    circDot4 = Circle(Point(75, 75), 5).setFill('black')

    circDot4.draw(win)

if intNum == 2:

    circDot2 = Circle(Point(50, 75), 5).setFill('black')

    circDot2.draw(win)

    circDot6 = dot().clone()

    circDot6.move(50, 0)

    circDot6.draw

if intNum == 3:

    circDot3 = Circle(Point(50, 100), 5).setFill('black')

    circDot3.draw(win)

    circDot4 = Circle(Point(75, 75), 5).setFill('black')

    circDot4.draw(win)

    circDot5 = Circle(Point(100, 50), 5).setFill('black')

    circDot5.draw(win)

if intNum == 4:

    circDot1 = Circle(Point(50, 50), 5).setFill('black')

    circDot1.draw(win)

    circDot3 = Circle(Point(50, 100), 5).setFill('black')

    circDot3.draw(win)

    circDot5 = Circle(Point(100, 50), 5).setFill('black')

    circDot5.draw(win)

    circDot7 = Circle(Point(100, 100), 5).setFill('black')

    circDot7.draw(win)

if intNum == 5:

    circDot1 = Circle(Point(50, 50), 5).setFill('black')

    circDot1.draw(win)

    circDot3 = Circle(Point(50, 100), 5).setFill('black')

    circDot3.draw(win)

    circDot5 = Circle(Point(100, 50), 5).setFill('black')

    circDot5.draw(win)

    circDot7 = Circle(Point(100, 100), 5).setFill('black')

    circDot7.draw(win)

    circDot4 = Circle(Point(75, 75), 5).setFill('black')

    circDot4.draw(win)

if intNum == 6:

    circDot1 = Circle(Point(50, 50), 5).setFill('black')

    circDot1.draw(win)

    circDot3 = Circle(Point(50, 100), 5).setFill('black')

    circDot3.draw(win)

    circDot5 = Circle(Point(100, 50), 5).setFill('black')

    circDot5.draw(win)

    circDot7 = Circle(Point(100, 100), 5).setFill('black')

    circDot7.draw(win)

    circDot2 = Circle(Point(50, 75), 5).setFill('black')

    circDot2.draw(win)

    circDot6 = dot().clone()

    circDot6.move(50, 0)

    circDot6.draw

def dice(win):

#make a square to represent the die and draw it

sqrDice = Rectangle(Point(25, 25), Point(125,125))

sqrDice.setFill('snow')

sqrDice.setOutline('snow')

sqrDice.draw(win)

dot()

def main():

win = GraphWin('Dice', 650, 400)

#papayawhip

win.setBackground('papayawhip')

blnRun = True

Box1 = Rectangle(Point(25, 25), Point(125, 125))

Box1.setFill('ivory')

Box1.draw(win)

Box2 = Rectangle(Point(150, 25), Point(250, 125))

Box2.setFill('ivory')

Box2.draw(win)

Box3 = Rectangle(Point(275, 25), Point(375, 125))

Box3.setFill('ivory')

Box3.draw(win)

Box4 = Rectangle(Point(400, 25), Point(500, 125))

Box4.setFill('ivory')

Box4.draw(win)

Box5 = Rectangle(Point(525, 25), Point(625, 125))

Box5.setFill('ivory')

Box5.draw(win)

while blnRun == True:

#get the x and y coordinates of a click

    ClickXY = win.getMouse()

    xPoint = ClickXY.getX()

   yPoint = ClickXY.getY()

#if they clicked within the button, call the dice function

    if xPoint > 25 and xPoint < 125 and yPoint > 25 and yPoint < 125:

        dice(win)

    elif xPoint > 150 and xPoint < 250 and yPoint > 25 and yPoint < 125:

        dice(win)

    elif xPoint > 275 and xPoint < 375 and yPoint > 25 and yPoint < 125:

        dice(win)

    elif xPoint > 400 and xPoint < 500 and yPoint > 25 and yPoint < 125:

        dice(win)

    elif xPoint > 525 and xPoint < 625 and yPoint > 25 and yPoint < 125:

        dice(win)

    else:

         Text(Point(200,325),"Click on a die").draw(win)

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