Task 1.
Suppose you have found the following (incomplete) Python code on a scrap of paper. It isn’t quite
finished and contains some errors.
def sort(L)
i = 1
k = len(L)-2
while (i<k)
a = i
b = k
if (L[b]<L[a])
# now swap L[a] and L[b]
for j in range(i,k+1)
if (L[j]<L[a])
a = j
if (L[j]>L[b])
b = j
# now swap L[i] and L[a] if a!=i
# now swap L[k] and L[b] if b!=k
i += 1
k -= 1
(1) Give a detailed critique of the incomplete code given above. Implement (in Python) the three
lines that swap values, fix any syntax errors so that the Python code runs, ensure the code
follows Python coding style, improve the names of the variables, and add useful comments.
Please annotate the existing code to show the syntax errors and provide a corrected version of
the code. Do not fix any semantic errors and be careful about the indenting already given.
[10 marks]
(2) Add appropriate print statements to the Python code from part (1) to generate (directly from
the code) a clear nontrivial example illustrating the algorithm running (think of it as a
commentary of a live example). The level of detail should show what comparisons are being
made and what decisions are being taken. Please provide both code (with print statements
added) and the output from the code running in a way that illustrates the algorithm. You can
also add additional text explanation to your example.
[5 marks]
(3) Insert additional Python code to count the number of comparisons and swaps of elements of
the list. Make improvements (with justification) to the code to improve its effectiveness (so
that it actually does solve the task, fixing any semantic errors) and efficiency (solves the task
using fewer operations). Explain what task the code is attempting to solve and the idea behind
the algorithm. Compare the improved algorithm with another (simpler) algorithm that solves
the same task. Clearly state the criteria you are using to judge your improvements. Test your
final Python code on some larger and more complex examples.
Task 2.
Escape is a simple dice game for one player. The player starts with their token on a grid at location
(0,0) in Cartesian coordinates. Rolling an unbiased four-sided dice, a 1 moves the token one unit North,
a 2 moves the token one unit East, a 3 moves the token one unit South, and a 4 moves the token one
unit West. A square boundary fence has four corners at (π, π), (π, −π), (−π, −π) and (−π, π) for some
whole numbered value π chosen before the game begins. The game stops when the player’s token
moves outside the boundary fence, i.e., escapes.
Before you write any code, it is worth playing this game a few times using a pencil, paper and a foursided dice (or use https://rolladie.net/roll-a-d4-die). Choose a value for π before your start (say π = 3)
and draw the corresponding boundary fence on squared paper.
(1) Implement this game as one Python function. Follow the steps and logic you take in a physical
game. Your code should include enough print statements to generate a clear nontrivial
example illustrating a play of the game, telling the story as the dice is rolled and the player’s
token moves. Please provide both your code and the output from a sample run.
[10 marks]
(2) Modify your code to add at least three counts that effectively summarise a game, e.g., how
many dice rolls are made before escaping, and the number of times the token returns to the
start location (0,0). Explore how these counts change with the size of the grid for values of the
parameter π from 1 to 5. Use these summary counts to compare the original game described
above with one further variant of the game of your choice. Explain carefully what steps you
have taken to test your code (not just debugging). Please provide your updated code for the
original game (with counts) and the variant, together with output from sample runs of each and
a comparison of counts in a table corresponding to different grid sizes.
[15 marks]
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme