Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Subject: Advanced Algorithms Due Date: Sat 29 Sept Submit it printed in a suitab

ID: 3754861 • Letter: S

Question

Subject: Advanced Algorithms Due Date: Sat 29 Sept Submit it printed in a suitable format (not written in hands) A junior park run event is held every week on a Saturday morning in a local park over a distance of two kilometers Children between the ages of 4 and 14 inclusive can register to take part. Children register with their name and age. When they register, they are allocated a unique identification number of four digits; the last digit is a check digit. Once registered a child can take part in the junior park run events for a year. For each event, the organizers record the time each child takes to run two kilometers. Their time is stored for every event they complete and the number of runs they have completed is updated by one. If their time is faster than their personal best (PB) time, their PB time is updated. When a child has completed 11 runs, they are awarded a half-marathon wristband. When a child has completed 22 runs, they are awarded a full-marathon wristband. A program is required to update the children's data, update PB times if necessary, and decide if a wristband is to be awarded. The program also needs to identify the fastest child at this event for each of the age ranges: 4 to 6, 7 to 10, and 1 to 14. Write and test an algorithm (pseudocode) do the following tasks: Task 1- Registration to take part Write a program to set up arrays to store the data for 20 children. On registration, each child must be allocated a unique identification number of four digits; the last digit is a check digit. The unique identification number, age in years and names for each child is recorded and stored on registration. The PB time and the number of runs are initialized to zero and these values stored on registration. Their PB time is stored as minutes correct to two decimal places. Task 2- Recording the times Extend your algorithm to record the unique identification number and to input the start time and finish time for every child completing the junior park run event.C store the time each child took to complete the run. A registered child does not have to compete in each event Only one time per child is recorded during an event. Task 3- Updating the children's data and identifying the fastest child for each age range Extend your algorithm to update the number of runs and the PB time if necessary for every child completing the junior park run event. Check if any half- or full-marathon wristbands need to be awarded. Output the names and the type of wristbands. Output the names and the time of the fastest child at this event for each of the age ranges 4 to 6, 7 to 10 and 11 to 14. Calculate and

Explanation / Answer

import random

class Child():

def __init__(self,name,age):

self.age = age

self.name = name

self.uid = self.generateUID()

self.records = []

self.awards = []

self.personal_best = 0.00

self.num_of_runs = 0

def createCheckDigit(self,firstDigit,secondDigit,thirdDigit):

oddSum = firstDigit+thirdDigit

oddSum*=3

evenSum = secondDigit

evenOddSum = oddSum+evenSum

reminder = evenOddSum%10

if(reminder!=0):

reminder = 10-reminder

return reminder

def generateUID(self):

firstDigit = random.randint(1,9)

secondDigit = random.randint(0,9)

thirdDigit = random.randint(0,9)

checkDigit = self.createCheckDigit(firstDigit,secondDigit,thirdDigit)

UID = firstDigit*1000+secondDigit*100+thirdDigit*10+checkDigit

return UID

def checkAwarded(child):

if(child.num_of_runs==11):

print("Hi",child.name,"You Have Won Half-Marathon Wristband")

child.awards.append("Half-Marathon Wristband")

elif(child.num_of_runs==22):

print("Hi",child.name,"You Have Won Full-Marathon Wristband")

child.awards.append("Full-Marathon Wristband")

def checkPersonalBest(child):

lastRun = child.records[child.num_of_runs-1]

if(lastRun<child.personal_best):

print("Hi",child.name,"Your Personal Best is updated.",lastRun)

child.personal_best = lastRun

def getUID(uid):

l = len(children)

for i in range(l):

if(children[i].uid==uid):

return children[i]

return 0

def eventRecord():

print("========= Event Started Please Enter Uid and Completed Time of Child =========")

choice = 1

while(choice):

uid = int(input("Enter Child UID: "))

kid = getUID(uid)

if(kid):

time = float(input("Enter Race completed Time: ").strip())

kid.num_of_runs+=1

if(kid.num_of_runs==1):

kid.personal_best = time

kid.records.append(time)

checkAwarded(kid)

checkPersonalBest(kid)

else:

print("Entered UID not found")

choice= int(input("Enter 1 to continue,0 to exit"))

def getFastest():

fast_4_6 =fast_7_10=fast_11_14= 99999

fast_4_6_pos =fast_7_10_pos=fast_11_14_pos = -1

for i in range(len(children)):

if(4<=children[i].age<=6 and fast_4_6>children[i].personal_best):

fast_4_6 = children[i].personal_best

fast_4_6_pos = i

if(7<=children[i].age<=10 and fast_7_10>children[i].personal_best):

fast_7_10 = children[i].personal_best

fast_7_10_pos = i

if(11<=children[i].age<=14 and fast_11_14>children[i].personal_best):

fast_11_14 = children[i].personal_best

fast_11_14_pos = i

print("Fastest Among 4-6 age.....")

print(children[fast_4_6_pos].uid,"||",children[fast_4_6_pos].name,"||",children[fast_4_6_pos].age,"||",children[fast_4_6_pos].num_of_runs)

print("Fastest Among 7-10 age.....")

print(children[fast_7_10_pos].uid,"||",children[fast_7_10_pos].name,"||",children[fast_7_10_pos].age,"||",children[fast_7_10_pos].num_of_runs)

print("Fastest Among 11-14 age.....")

print(children[fast_11_14_pos].uid,"||",children[fast_11_14_pos].name,"||",children[fast_11_14_pos].age,"||",children[fast_11_14_pos].num_of_runs)

def printRecords():

print("UID Name age num_of_runs personal_best Awards ")

for i in range(len(children)):

print(children[i].uid,"||",children[i].name,"||",children[i].age,"||",children[i].num_of_runs,"||",children[i].personal_best,"||",children[i].awards)

children = []

n = int(input("Enter Number of Children: "))

for i in range(n):

name = input("Enter Name of Child: ").strip()

age = int(input("Enter Age of Child: ").strip())

obj = Child(name,age)

children.append(obj)

print("========= Registration Completed.Displaying Children Data ========= ");

printRecords()

eventRecord()

print("========= Event Completed.Displaying Children Data ========= ");

printRecords()

getFastest()