Flik is a smart digital ant. Write a python progrem that helps Flik to move in 4 directions: East, West, North, and South (Scc figure 1), just like we did with the Turtle, but be careful, you are not going to usc graphics windows, and you are not going to usc any of the methods in the Turtle module for that matter, All the West X-axis 0,0) East outputs should be printed on the IPython Console panc. 2. Ant position: The current position of the bug is represented in a two-dimensional planc as a pair of coordinates (x, y) in the Cartesian coordinate system shown in figure 1. South Figure 1: Coordinates system 3. Tasks: The bug can perform the following tasks: Move cast (i.e. to the right) byn steps. It requires updating the current position of the bug to the new position n steps to the right. Move west (i.c. 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.c. 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 PI= (xl, yl) and P2 = (x2, y2) is: d = (x1- x2)2 + (yl-y2)2 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: [in meter]. For instance: north 5 means move north Once the reading is completed, the program displays the following: See Figure 2(b) 5 meters. The initial position of the ant Flik, The path Flik has followed ie the sequence of the successive bug's positions from its initial position to its final position, Flik's final position, and

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Use Python
Flik is a smart digital ant. Writc a python progrem that helps Flik
to move in 4 dircctions: East, West, Narth, and South (Sce
figure 1), just like we did with the Turtle, but be carcful, you are
not going to usc graphics windows, and you are not going to use
any of the mcthods in the Turtle module for that matter, All the
outputs should be printed on the IPython Console panc.
West
-axis
East
0,0)
2. Ant position: The current position of the bug is represented in a
two-dimensional planc as a pair of coordinatcs (x, y) in the
Cartesian coordinate systcm shown in figure 1.
South
Figure 1: Coordinates system
3. Tasks: The bug can perform the following tasks:
Move cast (i.c. to the right) byn steps. It requires updating the current position of the bug to the
new position n steps to the right.
Move west (i.c. 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.c. upward) by n steps. It requires updating the current position of the bug to the
new position n steps upward.
Move south (i.c. 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 PI= (xl, yl) and P2 = (x2, y2) is:
d = (x1 x2)² +(yl-y2)²
4. Program
Your program should perform the following tasks:
Read from a file called bugMoves.txt the initial position (x, v) 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 mcans move north by 5 meters.
Once the reading is completed, the program displays the following See Figure 2(b)
Ac
The initial position of the ant Flik
The path Flik has followed ie the sequence of the successive bug's positions from its .
initial position to its final position,
Flik's final posilion, and
The Euclidian distance separating Flik from its original position
Transcribed Image Text:Flik is a smart digital ant. Writc a python progrem that helps Flik to move in 4 dircctions: East, West, Narth, and South (Sce figure 1), just like we did with the Turtle, but be carcful, you are not going to usc graphics windows, and you are not going to use any of the mcthods in the Turtle module for that matter, All the outputs should be printed on the IPython Console panc. West -axis East 0,0) 2. Ant position: The current position of the bug is represented in a two-dimensional planc as a pair of coordinatcs (x, y) in the Cartesian coordinate systcm shown in figure 1. South Figure 1: Coordinates system 3. Tasks: The bug can perform the following tasks: Move cast (i.c. to the right) byn steps. It requires updating the current position of the bug to the new position n steps to the right. Move west (i.c. 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.c. upward) by n steps. It requires updating the current position of the bug to the new position n steps upward. Move south (i.c. 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 PI= (xl, yl) and P2 = (x2, y2) is: d = (x1 x2)² +(yl-y2)² 4. Program Your program should perform the following tasks: Read from a file called bugMoves.txt the initial position (x, v) 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 mcans move north by 5 meters. Once the reading is completed, the program displays the following See Figure 2(b) Ac The initial position of the ant Flik The path Flik has followed ie the sequence of the successive bug's positions from its . initial position to its final position, Flik's final posilion, and The Euclidian distance separating Flik from its original position
5. Exception Handling:
Handle IO exccption when trying to open file that docs not cxist.
The 2D coordinates (x, y) of the bug's initial position i.c.; the first line of the input file must be
integer numbers. In case the first line in the file contains floats, or non-digit characters, your
program should raisc a ValueError cxception and the original position is set to (0,0) by
default. Sce figure 3.
The number of steps to be exccuted by the bug should be a positive integer. In casc the file
contains crroncous valucs, your program should raise a ValueError cxccption and the
instruction is simply ignored. See figure 3.
6. Input/Output
Case 1: Input/Output corresponding to the case of error-free file bugMoves.txt with no exceptions
bugMoves.tat
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 >>>
I an at my final position (6, 15)
I om 5.00 meters from the initial position
Nice working with you...Bye!
(b) Output corresponding to the Error-free input file
Acti
Figure 2: Inpu/Output with no exceptions
Transcribed Image Text:5. Exception Handling: Handle IO exccption when trying to open file that docs not cxist. The 2D coordinates (x, y) of the bug's initial position i.c.; the first line of the input file must be integer numbers. In case the first line in the file contains floats, or non-digit characters, your program should raisc a ValueError cxception and the original position is set to (0,0) by default. Sce figure 3. The number of steps to be exccuted by the bug should be a positive integer. In casc the file contains crroncous valucs, your program should raise a ValueError cxccption and the instruction is simply ignored. See figure 3. 6. Input/Output Case 1: Input/Output corresponding to the case of error-free file bugMoves.txt with no exceptions bugMoves.tat 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 >>> I an at my final position (6, 15) I om 5.00 meters from the initial position Nice working with you...Bye! (b) Output corresponding to the Error-free input file Acti Figure 2: Inpu/Output with no exceptions
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY