Download (right-click, save target as ...) this page as a jupyterlab notebook from: Lab4


Laboratory 4: Sequence, Selection, and Repetition - Oh My!

LAST NAME, FIRST NAME

R00000000

ENGR 1330 Laboratory 4 - Homework

Exercise 1 : Find the Treasure Part 1

Consider the structure below (a treasure map)

              +-------------------------+
              ¦ 34 ¦ 21 ¦ 32 ¦ 41 ¦ 25  ¦
              +----+----+----+----+-----¦
              ¦ 14 ¦ 42 ¦ 43 ¦ 14 ¦ 31  ¦
              +----+----+----+----+-----¦
              ¦ 54 ¦ 45 ¦ 52 ¦ 42 ¦ 23  ¦
              +----+----+----+----+-----¦
              ¦ 33 ¦ 15 ¦ 51 ¦ 31 ¦ 35  ¦
              +----+----+----+----+-----¦
              ¦ 21 ¦ 52 ¦ 33 ¦ 13 ¦ 23  ¦
              +-------------------------+

In this problem you are to write a program to explore the above array for a treasure. The values in the array are clues. Each cell contains an integer between 11 and 55; for each value the ten's digit represents the row number and the unit's digit represents the column number of the cell containing the next clue. Starting in the upper left corner (at 1,1), use the clues to guide your search of the array. (The first three clues are 11, 34, 42). The treasure is a cell whose value is the same as its coordinates. Your program must first read in the treasure map data into a 5 by 5 array. Your program should output the cells it visits during its search, and a message indicating where you found the treasure.

The "Treasure Hunt Problem" is from the HackerRank.com avaiable at https://www.hackerrank.com/contests/startatastartup/challenges/treasure-hunt

Now for your problem we have not yet learned how to read from files, its a small problem so lets just construct the map manually by a sequence of expressions; Ive done the first two rows, so you only have to complete the script.

Exercise 2: A RoboCop Selects Your Speeding Ticket Amount

You are driving too fast, and a robotic police officer stops you. The robot is programmed with conditional statements to return one of 3 possible results: "No ticket","One hundred dollar fine", or "Five hundred dollar fine". according to the following rules

You discover you are able to hack into the robot and can modify the fine script.

Modify it so that:

Leave the rest unchanged.

Exercise 1 Part 2 -- Adding Some Selection

Using your treasure map script a selection statement that tests if a cell contains treasure (does the cell value agree with the row and column index), but it needs useful messages - add the messages.


Exercise 3: A Loop for Leaps!

1904 was a leap year. Create a script that prints out all the leap years from in the 20th century (1904-1999).


Exercise 4: Whats your sine?

Print a table of the sines of angles (in radians) between 0 and 1.57 with steps of 0.01. The script below might help (it will need modification!)


Exercise 5: Cutting Corners!

Consider the script below, it produces a triangle of lower case 'x' that is 13 lines tall. Modify the script to allow:

  1. The user to specify the number of lines (bigger than zero, and less than some upper bound, 40 is probably good so everything fits on the screen.
  2. The user can specify the character, such as 'x' or 'X' or an 'O' or some other printable character.

Exercise 5: Calling in Different Markers

Modify your solution above to produce:

W
WW
WWW
WWWW
WWWWW
WWWWWW
WWWWWWT
WWWWWWTT
WWWWWWTTT
WWWWWWTTTT
WWWWWWTTTTT
WWWWWWTTTTTF
WWWWWWTTTTTFF
WWWWWWTTTTTFFF
WWWWWWTTTTTFFFF
WWWWWWTTTTTFFFFF
WWWWWWTTTTTFFFFFF
WWWWWWTTTTTFFFFFFF

where the 'W','T','F' are user inputs.

Exercise 1 : Part 3 - Completing the Hunt

Now using your script from Part 2, and the example below (incomplete - thats your job) insert your selection script code into the appropriate place and find the treasure. (i.e. Have your script visit every cell and test for treasure)

              +-------------------------+
              ¦ 34 ¦ 21 ¦ 32 ¦ 41 ¦ 25  ¦
              +----+----+----+----+-----¦
              ¦ 14 ¦ 42 ¦ 43 ¦ 14 ¦ 31  ¦
              +----+----+----+----+-----¦
              ¦ 54 ¦ 45 ¦ 52 ¦ 42 ¦ 23  ¦
              +----+----+----+----+-----¦
              ¦ 33 ¦ 15 ¦ 51 ¦ 31 ¦ 35  ¦
              +----+----+----+----+-----¦
              ¦ 21 ¦ 52 ¦ 33 ¦ 13 ¦ 23  ¦
              +-------------------------+