Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python 2.7 please (20 Points) Write a class Bug that models a bug that moves along a 1D line. The bug moves either to the

python 2.7 pleaseimage text in transcribed

(20 Points) Write a class Bug that models a bug that moves along a 1D line. The bug moves either to the right or left. Initially, the bug moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide the constructor method: def init_(self, initialPosition) and the methods turn (), move (), position(), and direction (). Example usage: ant = Bug(10) # starts at position 10 facing right ant.move() # Position is11 ant.turn() # now facing left ant.nove() #Position is 10 ant.nove() #Position is 9 print ant.position() #prints '9, to the screen print ant. direction() # prints left, to the screen . Write a small test function that uses your class to make the bug move and turn a few times. This test program should print out the actual and expected positions

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

More Books

Students also viewed these Databases questions

Question

Explain the various techniques of Management Development.

Answered: 1 week ago