1. Problem Statement: North Flik is a smart digital ant. Write a python program that helps Flik to move in 4 directions: East, West, North, and South (See figure 1), just like we did with the 7Turtle, but be careful, you are West fast 0.0) not going to use graphics windows, and you are not going to use any of the methods in the Turtle module for that matter. All the outputs should be printed on the IPython Console pane. 2. Ant position: The current position of the bug is represented in a two-dimensional plane as a pair of coordinates (x, y) in the Figure I: Coordinates system Cartesian coordinate system shown in figure I. South 3. Tasks: The bug can perform the following tasks: • Move cast (i.e. to the right) by a steps. It requires updating the current position of the bug to the new position a steps to the right • Move west (ie. to the left) by a steps, It requires updating the current position of the bug to the new position a steps to the left. o Move north (ie. upward) by a steps. It requires updating the current position of the bug to the new position a steps upward. • Move south (i.e. downward) by a steps. It requires updating the current position of the bug to the new position a steps downward. o 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- 2, y2) is: d= Jri - 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: [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) G The initial position of the ant Flik, • The path Flik has followed ie; the soquence of the successive bug's positions from its initial position to its final position, • Flik's final position, and o The Euclidian distance separating Flik from its original position. 5. Exception Handling: o Handle 10 exception when trying to open file that does not exist. O The 2D coordinates (x, y) of the bug's initial position ie; the first line of the input file must be intege numbers. In case the first line in the file contains floats, or non-digit characters, your program should raise a ValueError exception and the original position is set to (0,0) by default. See figure 3. • The number of steps to be executed by the bug should be a positive integer. In case the file contains erroneous values, your program should raise a ValueError exception and the instruction is simply ignored. See figure 3. 6. Input/Output Case I: Input Output corresponding to the case of eror-free file bugMoves.txt wit. dons 10 12 east 1 north 5 west 3 south 1 west 2 south 1 (a) Error-free input file Fick Hello, I an Flick the snart ant!!! I an waiting for your instructions... Flick I an 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 I an at my final position (6, 15) FLick I an 5.00 meters fron the initial position Flick Nice working with you...Byet (b) Output corresponding to the Errer-free input file
1. Problem Statement: North Flik is a smart digital ant. Write a python program that helps Flik to move in 4 directions: East, West, North, and South (See figure 1), just like we did with the 7Turtle, but be careful, you are West fast 0.0) not going to use graphics windows, and you are not going to use any of the methods in the Turtle module for that matter. All the outputs should be printed on the IPython Console pane. 2. Ant position: The current position of the bug is represented in a two-dimensional plane as a pair of coordinates (x, y) in the Figure I: Coordinates system Cartesian coordinate system shown in figure I. South 3. Tasks: The bug can perform the following tasks: • Move cast (i.e. to the right) by a steps. It requires updating the current position of the bug to the new position a steps to the right • Move west (ie. to the left) by a steps, It requires updating the current position of the bug to the new position a steps to the left. o Move north (ie. upward) by a steps. It requires updating the current position of the bug to the new position a steps upward. • Move south (i.e. downward) by a steps. It requires updating the current position of the bug to the new position a steps downward. o 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- 2, y2) is: d= Jri - 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: [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) G The initial position of the ant Flik, • The path Flik has followed ie; the soquence of the successive bug's positions from its initial position to its final position, • Flik's final position, and o The Euclidian distance separating Flik from its original position. 5. Exception Handling: o Handle 10 exception when trying to open file that does not exist. O The 2D coordinates (x, y) of the bug's initial position ie; the first line of the input file must be intege numbers. In case the first line in the file contains floats, or non-digit characters, your program should raise a ValueError exception and the original position is set to (0,0) by default. See figure 3. • The number of steps to be executed by the bug should be a positive integer. In case the file contains erroneous values, your program should raise a ValueError exception and the instruction is simply ignored. See figure 3. 6. Input/Output Case I: Input Output corresponding to the case of eror-free file bugMoves.txt wit. dons 10 12 east 1 north 5 west 3 south 1 west 2 south 1 (a) Error-free input file Fick Hello, I an Flick the snart ant!!! I an waiting for your instructions... Flick I an 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 I an at my final position (6, 15) FLick I an 5.00 meters fron the initial position Flick Nice working with you...Byet (b) Output corresponding to the Errer-free input file
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...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 6 images
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY