Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 10, Problem 3PE
Program Plan Intro

Three Button Monte

Program Plan:

  • Import the required packages.
  • Declare a main function. Inside the main function,
    • Create the application window.
    • Draw the interface widget by creating three buttons.
    • Assign the text to the interface.
    • Call the method “draw()”.
    • Get the random number.
    • Assign the values to “false”.
    • Check the condition.
      • Assign “point1” to “true”.
    • Check the condition.
      • Assign the “point2” to “true”.
    • Otherwise, Assign the “point3” to “true”
    • Activate all the three doors.
    • Get the action mouse clicked.
    • Check the condition using “while” loop.
      • Check the condition for selecting the door 1 to be clicked.
      • Check the condition for selecting the door 2 to be clicked.
      • Check the condition for selecting the door 3 to be clicked.
    • Call the “getMouse()” function
  • Call the main function.

Expert Solution & Answer
Check Mark

Explanation of Solution

Program:

Refer the program “button.py” given in the “Chapter 10” from the text book. Add the method “update()” along with the given code.

#Define the method update

    def update(self, win, label):

        #Call the method undraw()

        self.label.undraw()

        #Assign the position to centre

        center = self.center

        #Assign the label

        self.label = Text(center, label)

        #Set active to false

        self.active = False

        #Call the method draw()

        self.label.draw(win)

Main.py:

#Import the required packages

from button import Button

from graphics import GraphWin, Point, Text

from random import random

#Definition of main method

def main():

   #Creating the application window by setting title, cords and background

    win = GraphWin("Three Button Monte", 500, 300)

    win.setCoords(-12, -12, 12, 12)

    win.setBackground("green3")

    #Draw the interface widget by creating three button

    door1 = Button(win, Point(-7.5, -3), 5, 6, "Door 1")

    door2 = Button(win, Point(0, -3), 5, 6, "Door 2")

    door3 = Button(win, Point(7.5, -3), 5, 6, "Door 3")

    #Assign the text to the interface

    direction = Text(Point(0, 10), "Pick a Door")

    #Call the method draw

    direction.draw(win)

    #Get the random number

    x = random() * 3

    #Assign the values to false

    point1 = point2 = point3 = False

    #check the condition

    if 0 <= x <1:

        #Assign point1 to True

        point1 = True

        #Chcek the condition

    elif 1 <= x < 2:

        #Assign the point2 to True

        point2 = True

        #Otherwise

    else:

        #Assign the point3 to True

        point3 = True

    #Activate all the three doors

    door1.activate()

    door2.activate()

    door3.activate()

    #Get the action mouse click

    click = win.getMouse()

#Check the condition using "while" loop

    while door1.clicked(click) or door2.clicked(click) or door3.clicked(click):

    #If door1 is clicked

        if door1.clicked(click):

            #Assign point1 to true

            if point1 == True:

                #Update the interface

                door1.update(win,"Victory!")

            else:

                 #If door1 is clicked

                if door2.clicked(click):

                     #Update the interface

                    door2.update(win,"Correct Door.")

                    #Get the action mouse click

                    click = win.getMouse()

                else:

                       #Update the interface

                    door3.update(win,"Correct door.")

                     #Get the action mouse click

                    click = win.getMouse()

             #If door2 is clicked        

        elif door2.clicked(click):

              #Assign point2 to true

            if point2 == True:

                  #Update the interface 

                door2.update(win,"Victory!")

            else:

                    #If door2 is clicked   

                if door3.clicked(click):

                    #Update the interface

                    door3.update(win,"Correct Door.")

                      #Get the action mouse click

                    click = win.getMouse()

                else:

                    #Update the interface 

                    door1.update(win,"Correct door.")

                      #Get the action mouse click

                    click = win.getMouse()

        else:

            #Assign point3 to true

            if point3 == True:

                 #Update the interface 

                door3.update(win,"Victory!")

            else:

                 #If door2 is clicked   

                if door2.clicked(click):

                    #Update the interface 

                    door2.update(win,"Correct Door.")

                    #Get the action mouse click

                    click = win.getMouse()

                else:

                     #Update the interface 

                    door1.update(win,"Correct door.")

            #Get the action mouse click

                    click = win.getMouse()

 #Call the getMouse()

    win.getMouse()

  #Call the main function 

main()

Sample Output

Output:

Screenshot of output

Python Programming: An Introduction to Computer Science, 3rd Ed., Chapter 10, Problem 3PE , additional homework tip  1

Screenshot of output

Python Programming: An Introduction to Computer Science, 3rd Ed., Chapter 10, Problem 3PE , additional homework tip  2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by  unit for each dose. How many doses of the potion must the character take to be able to jump all of the hurdles. If the character can already clear all of the hurdles, return . Example The character can jump  unit high initially and must take  doses of potion to be able to jump all of the hurdles. Function Description Complete the hurdleRace function in the editor below. hurdleRace has the following parameter(s): int k: the height the character can jump naturally int height[n]: the heights of each hurdle Returns int: the minimum number of doses required, always  or more Input Format The first line contains two space-separated integers  and , the number of hurdles and the maximum height the character can jump naturally.The…
In this game, the player is in a land full of dragons. The dragons all live in caves with their large piles of collected treasure. Some dragons are friendly and share their treasure. Other dragons are hungry and eat anyone who enters their cave. The player approaches two caves, one with a friendly dragon and the other with a hungry dragon, but doesn’t know which dragon is in which cave. The player must choose between the two.   The program should look like this in the console, the player input is in bold: You are in a land full of dragons. In front of you, you see two caves. In one cave, the dragon is friendly and will share his treasure with you. The other dragon is greedy and hungry and will eat you on sight. Which cave will you go into? (1 or 2)   1   You approach the cave... It is dark and spooky... A large dragon jumps out in front of you! He opens his jaws and... Gobbles you down in one bite!   Process finished with exit code 0 language java. please help me thanks
It is given 12 balls that are all the same weight except for one that is heavier or lighter. Additionally, it is provided with a two-pan balance. In each scenario, the balance is used. You may place any number of the 12 balls on the left pan and the same number on the right pan and press a button to begin weighing; three alternative results exist: the weights are equal, the balls on the left are heavier, or the balls on the left are lighter. Develop a technique for determining which ball is the odd one out and whether it is heavier or lighter than the others using the fewest feasible uses of the balance. Solve the weighing issue for the situation of 39 balls, one of which is known to be strange.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY