Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you please solve this program for me? I do not know where are the error. When I run the program, it says NameError: name

Could you please solve this program for me? I do not know where are the error. When I run the program, it says "NameError: name 'plotShot' is not defined"

image text in transcribed

And this is the requirement for the program:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

import math import random import tkinter # dimensions of the field FIELD_W600 FIELD_H600 # position and size of the pond POND-X = 300 PONDY300 POND R150 # number of shots to fire NUM_SHOTS100 def drawcircle(canvas, x, y, r, outline black, fill-white): canvas.create_oval(xl, yl, x2, y2, fill-fil l, outline-outline) def drawPond (canvas): drawCircle (canvas, POND_X, POND_Y, POND_R, 'blue) for x in range (300, 600, 50): plotShot (canvas, x, 300) def initWindow (title, width, height): master - tkinter. TkCO master.title(title) canvas-tkinter.Canvas (master, width-width, height-height) canvas.pack O return canvas def mainQ: canvas = initwindow("Monte drawPond (canvas) Carlo simulation", FIELD-W, FIELD-H) if _name_-main mainO tkinter.mainloop ) def hitPond (shotX, shotY) if math. sqrt ((shotX-POND-X) 2 (shotY-POND-Y) ** POND-R 2): ** + return True return False def plotShot (canvas, x, y): else: - hitPond(shotX, shotY) drawCircle(canvas, drawcircle(canvas. if h: x, y, r-5, fill 'blue')#blue else: x. v. r-5. fill 'areen ' ) #areen Shots that land in the pond will be drawn blue. Shots that land in the field will be drawn green This function does not simulate the firing of the shots. It only draws one small circle on the screen at a specified location and chooses the color appropriately. Later you'll add more functions that simulate the firing of multiple shots into the field Do this This function will place a visual indicator on the graphics window that shows a colored indication of whether a shot landed in the pond or in the field This function has these parameters 1. 2. 3. the canvas to draw on the x location of the shot the y location of the shot The function then must draw a circle of radius 5 in either green or blue depending on whether it landed in the pond or not. "In the pond" means that the distance from where the shot landed is less than or equal to the radius of the pond You might notice from the image above that some of the blue-filled circles on the edge of the pond appear to fall partly outside the pond, but what's happening is that the center of the shot (which is a single dimensionless point) falls within the pond, even though the blue-filled circle extends beyond the edge of the pond Here's an exaggerated view of what's happening The shot location is the black dot, which falls within the pond. But the way the shot is drawn as a blue-filled circle with radius 5, the circle extends a little outside the pond. A similar thing would happen if the shot fell just outside the pond: the green-filled circle would be drawn extending into the pond a bit I give a lot of hints about writing this function below, and even a function outline, but can Yes, I know that having all the information you need is not the same as knowing how to solve a problem, But give it your best shot The statements in the body of the function must do this: If the shot hit the pond, draw a blue-filled circle having radius 5, otherwise draw a green-filled circle having radius 5. You will need to use an if/else statement, and you will need to call the hitPond function and the drawCircle function Also, this function must return a result: It returns True if the shot landed in the pond. -It returns False if the shot landed in the field. Be very careful here: The function should not display True or False, it should return True or False. This is the function outline. You just need to fill it in: def plotShot(...) h-hitPond( if h: ) # save the True or False so we can return it later drawCircle(..) # blue clewr drawCircle(..) # green return h # return the True or False drawCircle( ) # blue else: draw:Circle( ) # green return h # return the True or False If you wrote the function on your own, then it does not need to look just like mine, as long as it works correctly 16 Test it Since the graphics window needs to be running in order to test the plotShot function, it will need to be done from within the main function instead of from the Python command prompt. Add these statements to the main function below the drawPond function call: for x in range(300, 600, 50): plotShot(canvas, x, 300) Notice what the values are that x is taking on: - 300, 350, 400, 450, 500, 550, 600 (oops, not 600) I start x at 300 because that's the x location of the center of the pond. Then I have the shots move outward from there. Run the program: for x in range(300, 600, 50) plotShot(canvas, x, 300) Notice what the values are that x is taking on: - 300, 350, 400, 450, 500, 550, 600 (oops, not 600) I start x at 300 because that's the x location of the center of the pond. Then I have the shots move outward from there Run the program: Masta Carlo Sm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions