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.
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()
Output:
Screenshot of output
Screenshot of output
Want to see more full solutions like this?
Chapter 10 Solutions
Python Programming: An Introduction to Computer Science
- You are hired by a game design company and one of their most popular games is The Journey. The game has a ton of quests, and for a player to win, the player must finish all the quests. There are a total of N quests in the game. Here is how the game works: the player can arbitrarily pick one of the N quests to start from. Once the player completes a quest, they unlock some other quests. The player can then choose one of the unlocked quests and complete it, and so on. For instance, let’s say that this game had only 4 quests: A, B, C, and D. Let’s say that after you complete • quest A, you unlock quests [B, D]. • quest B, you unlock quests [C, D]. • quest C, you unlock nothing [ ]. • quest D, you unlock quest [C]. Is this game winnable? Yes, because of the following scenario: The player picks quest A to start with. At the end of the quest A, the unlocked list contains [B, D]. Say that player chooses to do quest B, then the…arrow_forwardWrite a program that asks the user to enter a 1st color choice from a set of options: red, yellow or blue, and then asks them to enter a 2nd color choice from the remaining 2arrow_forwardNim is a two-player game played with several piles of stones. You can use as many piles and as many stones in each pile as you want, but in order to better understand the game, we'll start off with just a few small piles of stones (see figure 1 below). Pile 1 Pile 1 Pile 2 The two players take turns removing stones from the game. On each turn, the player removing stones can only take stones from one pile, but they can remove as many stones from that pile as they want (please note, a player must remove atleast 1 stone from a pile during his/her turn). If they want, they can even remove the entire pile from the game! The winner is the player who removes the final stone (avoid taking the last stone - see figure 2 below). Pile 2 Pile 3 Pile 3 Let's say its Max (player 1) turn to play. Then Max can win by simply removing a stone from Pile 2 or Pile 3 Draw a game tree (upto depth level 2) for the given version of the Nim game. Please consider figure 1 as your initial game configuration/state…arrow_forward
- There are a dozen eggs in a basket; some are hard boiled and some are raw. The object of this game is for the user to guess the number of hard-boiled eggs prior to playing the game. The computer then simulates cracking all 12 eggs, using a random number 0 or 1 to simulate raw or hard boiled. The number 0 should represent raw eggs and the number 1 should represent hard boiled. The computer must keep track of the number of hard-boiled eggs. At the conclusion of cracking all 12 eggs, the actual number of hard boiled is compared to the user’s guess, and whether the user won or lost is given as output. PreviousNextarrow_forwardYou are to write a program that allows the user to draw a simple house using 5 mouse clicks. - The first two clicks will be the opposite corners of the rectangular frame of the house. - The third click will indicate the center of the top edge of the rectangular door. The door should have a total width that is 1/5 of the width of the house frame. The sides of the door should extend from the corners of the top down to the bottom of the frame. - The 4th click will indicate the center of a square window. The window is as wide as the door. (A change from the original book program.) - The last click will indicate the peak of the roof. The edges of the roof will extend from the point at the peak to the corners of the top edge of the house frame. Make the lines of the roof edge green. (Another change from the original book program.)arrow_forwardIn the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: Rock beats scissors, because a rock can break a pair of scissors. Scissors beats paper, because scissors can cut paper. Paper beats rock, because a piece of paper can cover a rock. Create a game in which the computer randomly chooses rock, paper, or scissors. Let the user enter a number 1, 2, or 3, each representing one of the three choices. Then, determine the winner. Program should validate all user input Game should ask the user to play again and continue if yes and stop if no. Once the user stops playing, program should print the total number of wins.arrow_forward
- It is given twelve balls of identical weight with the exception of one that is either heavier or lighter. Additionally, it is equipped with a dual-pan balance. Utilization of the balance in each instance You may place any number of the 12 balls on the left pan and the same number on the right pan, and then press a button to begin weighing; there are three potential outcomes: the weights are equal, the balls on the left are heavier, or the balls on the left are lighter. Create a technique for determining which ball is the odd one out and whether it is heavier or lighter than the others using the balance in the fewest feasible instances. Solve the issue of weighing 39 balls, one of which is known to be odd.arrow_forwardA restaurant offers three options: A sandwich for BD2.500, with a reduction of 10% for orders of at least five sandwiches. A meal (sandwich, side, and drink) for BD3. Family meal for two adults and two or more children. The price is BD8.500 with an additional BD1.500 for each child beyond two children. Write a program that calculates the total price of tickets using a method and a switch statement. The program displays a menu with three options, lets the user select option, and then asks for the number of orders. It should then display the total amount due. Part 3: calculating your meal price Choose an option from the following menu: 1. Regular sandwich 2. Sandwich meal (sandwich, side, and drink) 3. Family meal 4. Quit Enter your choice (1-4): 1 Enter the number of regular sandwiches: 8 You total is BHD 18.000 Choose an option from the following menu: 1. Regular sandwich 2. Sandwich meal (sandwich, side, and drink) 3. Family meal 4. Quit Enter your choice (1-4): 3 Enter the number of…arrow_forwardAGU Computer Engineering Department created a new mathematical game that can be played with two people. In this game, you are given a list of random integers. At each round, the first player takes two numbers from the list and calculates the sum of these numbers. Then, the second player takes two numbers and makes the same calculation. The higher one is going to take the round and increment the score by 1. At the end of the game, who has the better score will win the game. Here are the rules for the game: There are always an even number of items on the list There are two colors for the players: Green and Red Green starts the game At each round, green plays and then red plays The player takes the first and the last numbers The game can end Tie when the scores are the same. The game will end when there is no element to take from the list Your program on java will simulate the rounds and find out the winner, Green or Red or Tie. The input will be two lines. Input…arrow_forward
- AGU Computer Engineering Department created a new mathematical game that can be played with two people. In this game, you are given a list of random integers. At each round, the first player takes two numbers from the list and calculates the sum of these numbers. Then, the second player takes two numbers and makes the same calculation. The higher one is going to take the round and increment the score by 1. At the end of the game, who has the better score will win the game. Here are the rules for the game: There are always an even number of items on the list There are two colors for the players: Green and Red Green starts the game At each round, green plays and then red plays The player takes the first and the last numbers The game can end Tie when the scores are the same. The game will end when there is no element to take from the list Your program will simulate the rounds and find out the winner, Green or Red or Tie. The input will be two lines. Input Format…arrow_forwardIn the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows:Rock beats scissors, because a rock can break a pair of scissors.Scissors beats paper, because scissors can cut paper.Paper beats rock, because a piece of paper can cover a rock.Create a game in which the computer randomly chooses rock, paper, or scissors.Let the user enter a number 1, 2, or 3, each representing one of the three choices.Then, determine the winner.Program should validate all user inputGame should ask the user to play again and continue if yes and stop if no.Once the user stops playing, program should print the total number of wins.arrow_forwardMad Libs is a game where the player selects words based on part of speech that are then used to fill in the missing words for a story. For instance, if I ask you for a noun, past‐tense verb, and another noun, you might say “CAT”, “BOUGHT”, “ZEBRA”. Those could be filled in to the story: “The some playdough and gave it to the ”, and you would end up with The cat bought some playdough and gave it to the zebra. Write a program in C# (and a story) to do a Mad Lib. Your story should be original… not something you find on the Internet. You need to read in a minimum of 10 words to add to your story. Once the words are entered, display the story on the console. Here’s an online one you can play for some inspiration: http://www.redkid.net/cgi‐bin/madlibs/caroftheyear.pl (but not TOO MUCH inspiration ‐‐ do not copy one of these!)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education