Engr 313 EGR 140: Computer Programming Assignment # 14: Due: Wednesday 28 October 2020 Points: 20 This is an attempt to write a fun program. Of course, no program appears fun if it entails a lot of...

See attachment.


Engr 313 EGR 140: Computer Programming Assignment # 14: Due: Wednesday 28 October 2020 Points: 20 This is an attempt to write a fun program. Of course, no program appears fun if it entails a lot of weeping and gnashing of teeth. But the goal is to write a simple race game. To keep it simple there will be minimal user interaction. Write an error-free Python program to do the following things. · Write a class Person (or Toddler or Student or DrunkSailor or whatever) that models a person moving along a horizontal line. The person moves either to the right or left. · Initially, the person moves to the right but at random times he/she will turn and change his/her direction. (For a student, the turns correspond to meeting friends that are moving in the opposite direction, so the student turns to walk with their friend. For a drunk sailor, he is trying to get back to the ship but he gets disoriented and lost. For a toddler he/she could be chasing a butterfly. Or you can make up your own scenario.) In each move, the object’s position changes by one unit in the current direction. · Provide an initializer that sets the initial position to a parameter, such as guidanceNeeded = Person(10) · Provide methods such as turn(), move(), display the position and any others that you need . · The main program should construct four objects (you must use an array), have them all start at position = 10 (you have to use the initializer/constructor). Ask the user to input the start position for the first object in the race and then set the position of the first object based on the user input. · The race objects turn approximately 30% of the time. Each object should turn independently of each other; that is, they do not necessarily turn at the same time. You need to use a random number generator to decide when an object turns. That is, at each time step, generate a random number and based on the value of the random number turn the direction of travel of the object. · Use a loop to make the objects move 10 times with an occasional turn (as noted above, turn approximately 30% of the time). Have a race between the objects and print the position of each object after each move. · In the middle of the race object 1 gives “help” to object 2 and object 3 gives help to object 4. So after 5 moves, set object 2 to the sum of object1 and object2 and object4 = object3 + object4. Write the code so that the “+” operator is used to add the objects. When two objects are added, add their positions and use the direction (left or right) of the object that provided the “help” – object1 (or object3) in this case. · At the end of 10 time steps, state a message specifying which object made it the furthest toward the library/ship/goal. · A few things I am expecting students to do with this program: (a) use an array of objects, (b) use the __str__ method to display information about object, (c) use + to add two objects. (d) most of the “work” will be done via methods within the class. · Note about grading: If you can get 1 object working (constructor, moving/turning for 10 time steps) then you will get (up to) 14 points. Thus, work on getting one object working then it should be straightforward to get the array of objects in a race and have objects help their neighbor. Sample output (initial position = 10): It is a race to the library. Cheer for your favorite What is the start location for student 1? 12 On your mark ... get set ... go! Student positions --------------------------------- After 1 steps: 13 11 11 11 After 2 steps: 12 12 12 12 After 3 steps: 11 13 11 13 After 4 steps: 12 14 12 14 After 5 steps: 13 13 11 15 A little help here After 6 steps: 14 25 10 25 After 7 steps: 15 26 9 24 After 8 steps: 16 27 8 23 After 9 steps: 15 28 9 24 After 10 steps: 14 29 10 23 Student 2 made it the farthest. Comment: Your output does not have to be exactly like this. The “little help here” just shows where the addition occurs but that statement does not need to be included. Also not that sometimes the numbers get bigger (object is moving right) and sometimes they get smaller (object is moving left). Remember to put the usual header at the top of the program and to submit via Canvas.
Oct 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here