Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
3rd Edition
ISBN: 9781590282779
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, Chapter 10, Problem 3PE , additional homework tip  1

Screenshot of output

Python Programming: An Introduction to Computer Science, 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
Please answer the homework scenario below and make a JAVA OOP code. You have been hired by GMU to create and manage their course registration portal. Your first task is to develop a program that will create and track different courses in the portal.  Each course has the following properties:  • a course number ex. IT 106, IT 206,  • A course description, ex. Intro to Programming • Total credit hour ex. 3.0, and  • current enrollment ex. 30 Each course must have at least a course number and credit hours. The maximum enrollment for each course is 40 students. The current enrollment should be no greater than the maximum enrollment. A course can have a maximum of 4 credit hour. The DDC should calculate the number of seats remaining for the course. Design an object-oriented solution to create a data definition class for the course object. The course class must define all the constructors, mutators with proper validation, accessors, and special purpose methods. The DDC should calculate the…
For this case study, students will analyze the ethical considerations surrounding artificial intelligence and big data in healthcare, as explored in the case study found in the textbook (pages 34-36) and in the extended version available here  There will also be additional articles in this weeks learning module to show both sides of the coin. https://www.delftdesignforvalues.nl/wp-content/uploads/2018/03/Saving-the-life-of-medical-ethics-in-the-age-of-AI-and-Big-Data.pdf   Students should refer to the syllabus for specific guidelines regarding length, format, and content requirements.   Reflection Questions to Consider: What are the key ethical dilemmas presented in the case? How does AI challenge traditional medical ethics principles such as autonomy, beneficence, and confidentiality? In what ways can responsible innovation help address moral overload in healthcare decision-making? What are the potential risks and benefits of integrating AI-driven decision-making into patient care?…
Can you please solve this. Thanks
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY