Past year papers
Past year papers
f.readline() to skip the first line of the file (e.g. if headers)
2022 Promos Q9 ryan’s ans: Untitled0.ipynb
Tic tac toe
# To check for wins (4 by 4):# ans key for task 4.4def checkWin(board, move, player):row, col = move# check rowwin = Truefor c in range(4):if board[row][c] not in (player, 'T'):win = Falseif win: return True# check colwin = Truefor r in range(4):if board[r][col] not in (player, 'T'):win = Falseif win: return True# check diagonal from left top to right bottomif row == col:win = Truefor i in range(4):if board[i][i] not in (player, 'T'):win = Falseif win: return True# check diagonal from left bottom to right topif row + col == 3:win = Truefor c in range(4):if board[3-c][c] not in (player, 'T'):win = Falseif win: return Truereturn False |
|---|
SQL


# for $.2dp (NOTE placement of ‘’)${{‘%0.2f**’**% item[2] }} |
|---|
SQL:
# To include those with 0 completed toosql5 = '''SELECT Stylist.StylistName, COUNT(Appointment.StylistNo) AS CompletedAppointments, (COUNT(Appointment.StylistNo) * Stylist.Price) AS TotalRevenue FROM Stylist LEFT OUTER JOIN Appointment ON Appointment.StylistNo = Stylist.StylistNo AND Appointment.Status = ‘Completed’ GROUP BY Stylist.StylistNo ''' ![]() |
|---|
OOP
class SmsServiceRecord(ServiceRecord):def __init__(self, Sender=None, AccessDate=None, Status=None):super().__init__(Sender, AccessDate, Status) |
|---|
class Queue(LinkedStructure):def __init__(self):LinkedStructure.Initialise(self) # super().Initialise() |
# Task 3.3sql = '''SELECT Cake.ProductCode, Name, Location, Price, ServingSize FROM Cake INNER JOIN Product ON Cake.ProductCode = Product.ProductCode WHERE Cake.Shape = “Circle” ''' cursor = bakerydb.execute(sql)print(f"Product Code\tName\tLocation\tPrice\tServing Size")for row in cursor:print(row) |
|---|
