Tasks: The bug can perform the following tasks: o Move east (i.e. to the right) by n steps. It requires updating the current position of the bug to the new position n steps to the right. o Move west (i.e. to the left) by n steps. It requires updating the current position of the bug to the new position n steps to the left. o Move north (i.e. upward) by n steps. It requires updating the current position of the bug to the new position n steps upward. o Move south (i.e. downward) by n steps. It requires updating the current position of the bug to the new position n steps downward. Calculate the Euclidian distance from the current position of the bug to its initial position. The Euclidian distance d between two points P1= (x1, yl) and P2 = (x2, y2) is: d = /(x1 – x2)² + (y1 – y2)² %3D

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
1-Flick is the name of a moving body 2-Use python.
6. Input/Output
Case 1: Input/Output corresponding to the case of error-free file bugMoves.txt with no exceptions
bugMoves.bt-
10 12
east 1
north 5
west 3
south 1
west 2
south 1
(a) Error-free input file
Flick >>> Hello, I am Flick the smart ant!!! I am waiting for your instructions...
Flick >>> I am at the initial position (10, 12)
Flick >>> This is my itinirary:
(10, 12)
(11, 12)
(11, 17)
(8, 17)
(8, 16)
(6, 16)
(6, 15)
Flick >>>
Flick >>>
Flick >>> Nice working with you...Bye!
I am at my final position (6, 15)
I am 5.00 meters from the initial position
(b) Output corresponding to the Error-free input file
Figure 2: Input/Output with no exceptions
Case 2: Input/Output corresponding to a file bugMoves.txt with errors. The code generates 3
exceptions related to erroneous values in the input file (line_1, line_2, and line_4).
goves.t ed
10 1.2
east 1.5
north 5
west b
south 1
west 2
south 1
(a) Input file with value errors in line_1, line_2, and line_4
Flick >>> Hello, I am Flick the smart ant!!! I am waiting for your instructions...
Oops: 20 coordinates of the bug should be integer !!
Initial position is set to (0,0)
Flick >>> I am at the initial position (0, 0)
Flick >>> This is my itinirary:
(0, 0)
Oops: Step value should be integer
The instruction is ignored.
(0, 0)
(0, 5)
Oops: Step value should be integer
The instruction is ignored.
(0, 5)
(0, 4)
(-2, 4)
(-2, 3)
Flick >>>
Flick >>> I am 3.61 meters from the initial position
Flick >>> Nice working with you...Bye!
I am at my final position (-2, 3)
(b) Output corresponding to an input file with value errors
Figure 3: Input/Output raising exceptions
Transcribed Image Text:6. Input/Output Case 1: Input/Output corresponding to the case of error-free file bugMoves.txt with no exceptions bugMoves.bt- 10 12 east 1 north 5 west 3 south 1 west 2 south 1 (a) Error-free input file Flick >>> Hello, I am Flick the smart ant!!! I am waiting for your instructions... Flick >>> I am at the initial position (10, 12) Flick >>> This is my itinirary: (10, 12) (11, 12) (11, 17) (8, 17) (8, 16) (6, 16) (6, 15) Flick >>> Flick >>> Flick >>> Nice working with you...Bye! I am at my final position (6, 15) I am 5.00 meters from the initial position (b) Output corresponding to the Error-free input file Figure 2: Input/Output with no exceptions Case 2: Input/Output corresponding to a file bugMoves.txt with errors. The code generates 3 exceptions related to erroneous values in the input file (line_1, line_2, and line_4). goves.t ed 10 1.2 east 1.5 north 5 west b south 1 west 2 south 1 (a) Input file with value errors in line_1, line_2, and line_4 Flick >>> Hello, I am Flick the smart ant!!! I am waiting for your instructions... Oops: 20 coordinates of the bug should be integer !! Initial position is set to (0,0) Flick >>> I am at the initial position (0, 0) Flick >>> This is my itinirary: (0, 0) Oops: Step value should be integer The instruction is ignored. (0, 0) (0, 5) Oops: Step value should be integer The instruction is ignored. (0, 5) (0, 4) (-2, 4) (-2, 3) Flick >>> Flick >>> I am 3.61 meters from the initial position Flick >>> Nice working with you...Bye! I am at my final position (-2, 3) (b) Output corresponding to an input file with value errors Figure 3: Input/Output raising exceptions
North
х-ахis
West
East
(0,0)
South
Figure 1: Coordinates system
3. Tasks: The bug can perform the following tasks:
Move east (i.e. to the right) by n steps. It requires updating the current position of the bug to the
new position n steps to the right.
Move west (i.e. to the left) by n steps. It requires updating the current position of the bug to the
new position n steps to the left.
Move north (i.e. upward) by n steps. It requires updating the current position of the bug to the
new position n steps upward.
Move south (i.e. downward) by n steps. It requires updating the current position of the bug to the
new position n steps downward.
Calculate the Euclidian distance from the current position of the bug to its initial position. The
Euclidian distance d between two points P1= (x1, yl) and P2 = (x2, y2) is:
d = /(x1 – x2)² + (y1 – y2)²
4. Program
Your program should perform the following tasks:
Read from a file called bugMoves.txt the initial position (x, y) of Flik
Then read line by line the remaining contents of the file and update the current position of Flik
accordingly, in order to build the path that Flick has followed from the start.
Each subsequent line in the file represents a movement to be performed by the bug, See figure
2 (a). The movement of the bug is specified by the pair: <direction> <the number of
steps> [in meter]. For instance: north 5 means move north by 5 meters.
Once the reading is completed, the program displays the following: See Figure 2(b)
The initial position of the ant Flik,
The path Flik has followed i.e.; the sequence of the successive bug's positions from its
initial position to its final position,
Flik's final position, and
The Euclidian distance separating Flik from its original position.
A- טSIX
Transcribed Image Text:North х-ахis West East (0,0) South Figure 1: Coordinates system 3. Tasks: The bug can perform the following tasks: Move east (i.e. to the right) by n steps. It requires updating the current position of the bug to the new position n steps to the right. Move west (i.e. to the left) by n steps. It requires updating the current position of the bug to the new position n steps to the left. Move north (i.e. upward) by n steps. It requires updating the current position of the bug to the new position n steps upward. Move south (i.e. downward) by n steps. It requires updating the current position of the bug to the new position n steps downward. Calculate the Euclidian distance from the current position of the bug to its initial position. The Euclidian distance d between two points P1= (x1, yl) and P2 = (x2, y2) is: d = /(x1 – x2)² + (y1 – y2)² 4. Program Your program should perform the following tasks: Read from a file called bugMoves.txt the initial position (x, y) of Flik Then read line by line the remaining contents of the file and update the current position of Flik accordingly, in order to build the path that Flick has followed from the start. Each subsequent line in the file represents a movement to be performed by the bug, See figure 2 (a). The movement of the bug is specified by the pair: <direction> <the number of steps> [in meter]. For instance: north 5 means move north by 5 meters. Once the reading is completed, the program displays the following: See Figure 2(b) The initial position of the ant Flik, The path Flik has followed i.e.; the sequence of the successive bug's positions from its initial position to its final position, Flik's final position, and The Euclidian distance separating Flik from its original position. A- טSIX
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education