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

Test cases for draw_die Test cases for instructions Test Cases for in_box There

ID: 3685708 • Letter: T

Question

Test cases for draw_die

Test cases for instructions

Test Cases for in_box

There could be several more based on the position of the point outside the box

Test cases for click_yes_or_no

Test cases for play_a_round

Test cases for main

Write a Python program to implement your design. Eliminate the syntax and semantics errors. Start with a copy of the design from Step 2. Write your code between the commented lines of the design. Use the same link at the top of this page to submit your source code when it is finished. Use the menu choices of "Code" and "Program 3".

This time I am not insisting you write a NON-graphical version first; but that is still my advice! It helps you get your logic straight.

Test your functions as you write them, using the test plan (see unit testing).

There are several specifications about how your program should be written.
You can arrange the elements of the game on the screen as you wish. You can choose colors as you like. The requirement is that all the information which is displayed in the sample screen shots must appear somewhere on the screen.
You can find or make your own gifs for the 6 numbers. You must use the filenames "1.gif", "2.gif", "3.gif", "4.gif", "5.gif" and "6.gif".

You may not use global variables at all (20 point penalty). ALL code must be in the scope of a function. The reason for this is that some people think they can make things easier when writing functions by not having any parameters, just "make everything global". This is bad practice, makes things harder in the long run, and is a bad habit to get into! Parameters are the data the function needs to do its job.

Imports, on the other hand, are expected to be near the top of the file, before any function definitions.

You must follow the guarantees of structured programming in all your code. This means for each function, there is either one or no return statement. If there is a return, it is at the bottom of the function, the last line in the definition. This also means that there are NO breaks, continues, infinite loops of ANY kind. The penalty can go up to 50 points.

You must write these functions (and use (call) them):

draw_die - a function that receives as parameters a number of a die (1-6) and two numbers that are the x,y coordinate for the middle of the image to draw, and one other parameter needed to do graphics in the function. This function draws the correct gif file for the desired die and also RETURNS the Image object that contains this gif file. This function is NO MORE THAN FOUR lines long, not counting comments. If you want to make it longer, stop and look at the code you are writing - is there a PATTERN in it? It does NOT use a random function at all.

instructions - a function with no parameters and no return value. Its job is to display a separate graphics window with the instructions for the game. It exists until the user clicks in it.

in_box - a function with three Points as parameters, the first two define a "box" = Rectangle. The function decides whether the third Point is between the first two, both the x coordinate and the y coordinate. It returns True if it is between and False otherwise.

play_a_round - a function with two parameters, the player number (1 or 2) and the graphics window object, which plays a round with that player This function shows the rolls as they happen, keeps track of how much the player wins in THIS ROUND ONLY, and sets that to zero if necessary.
it returns the amount that player won in the whole round (in their turn) - this number could be zero!

click_yes_or_no - a function with 2 parameters, the player number and the graphics window, that will draw two buttons (boxes) for Yes and No and let the user click on one of them. It also displays the prompt "Roll again Player #?" This function MUST call in_box! It returns True if the user clicked in the Yes box, returns False if they click in the No box, and ignores any other click!

main function - this function prepares the graphics window, calls the proper functions at the proper time with the correct arguments, keeps the game going until one of the players reaches 100 points. It gives an appropriate ending message depending on how the game ends.

You MUST use

a flag to record whether the user wants to roll again or not

You MUST NOT use

anything that breaks the guarantees of structured programming

such as a break

or a continue

or a while with an else?

or more than one return statement in a function definition

Please read the documentation standard. As you can see from looking at the grading sheet, we will be looking to see how you meet these standards. Note particularly that we require a header comment!

Description of Case Inputs
die number, location of center of image, window object Expected Output/Behavior/Return value normal case
die in middle of window 3, point in middle of window, window object gif picture of 3 die centered in graphics window object, returns Image object of that gif boundary clipping
die near edge of window 4, point in near edge of window, window object gif picture of 4 die near edge of graphics window object, part visible and part not, returns Image object of that gif boundary case
die number 1 in middle of window 1, point in middle of window, window object gif picture of 1 die centered in graphics window object, returns Image object of that gif boundary case
die number 6 in middle of window 6, point in middle of window, window object gif picture of 6 die centered in graphics window object, returns Image object of that gif

Explanation / Answer

Note:I have just written this code without using graphics. from __future__ import division import random import sys def dice_roll(): return random.randint(1, 6) def number_of_rolls(): return int(raw_input('Enter the number of rolls: ')) def simulate(number_of_times): counter = {n : 0 for n in range(2, 13)} doubles = 0 for i in range(number_of_times): first_dice = dice_roll() second_dice = dice_roll() total = first_dice + second_dice doubles += 0 if first_dice != second_dice else 1 counter[total] += 1 return counter, doubles def main(): rolls = number_of_rolls() counter, doubles = simulate(rolls) total = sum(counter.values()) for total, count in counter.items(): print("{} - {} {:0.4f}%".format(total, count, count / rolls * 100)) print("Doubles - {} - {:0.6f}%".format(doubles, doubles / rolls * 100)) if __name__ == '__main__': sys.exit(main())

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