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.4
def checkWin(board, move, player):
row, col = move
# check row
win = True
for c in range(4):
if board[row][c] not in (player, 'T'):
win = False
if win: return True
# check col
win = True
for r in range(4):
if board[r][col] not in (player, 'T'):
win = False
if win: return True
# check diagonal from left top to right bottom
if row == col:
win = True
for i in range(4):
if board[i][i] not in (player, 'T'):
win = False
if win: return True
# check diagonal from left bottom to right top
if row + col == 3:
win = True
for c in range(4):
if board[3-c][c] not in (player, 'T'):
win = False
if win: return True
return False

SQL

# for $.2dp (NOTE placement of ‘’)
${{%0.2f**’**% item[2] }}

SQL:

# To include those with 0 completed too
sql5 = '''
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.3
sql = '''
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)