Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Python Register Question

bobbyking876

New Coder
At this stage in the process the customer’s vehicle is sent to one of the available mechanics on dutyfor a preliminary assessment.assessVehicle: CustomerRegister, CID, SCL -> HHMMDuring this preliminary assessment, the mechanic will take into consideration some key factors thatwill affect the price of the service. The customer would have already indicated what the limit is thatthey are willing to pay (Pay Limit - PL). If the cost of the servicing goes over that limit by more than5%, the mechanic’s assessment cost should make a note on the register but remove the lowest costsfrom the list until it is within that 5% threshold.There is a servicing cost list which denotes the general cost for certain tasks or jobs to be done on avehicle based on the make (MK) of the vehicle. The servicing cost list is of the format🙁"CL", ([Mk, (FH, ET), (TC, ET), (ShT, ET)]))The servicing cost list is a tagged tuple with two elements; the first element is a tag "CL", andthe second element is a tuple of lists of servicing costs per each make of vehicle:• Mk – Make of Vehicle• FH – Full house check cost (float)• TC – Tyre Change cost (float)• ShT – shocks test cost (float)• ET – Estimated time for the service activity.Write a function assessVehicle()that accepts a customer register, customer Id and a servicingcost list as parameters, updates service cost and the estimated time for servicing in the customerrecord that matches the given customer Id, and returns the estimated pickup time HHMM as a stringin 24-hour format• If the vehicle is more than five years old and the make (Mk) is not a Benz, then the mechanicwill have to do a full house check.• A mileage over 100,000 will incur a shocks test if a full house is not being done.• Tyres will need to be changed if the last service date is more than 10 months ago.The estimated pickup time is five (5) minutes before the calculated time between the customer’sarrival time and service time.



This is the code up to part 3 but I can't solve part 4:

Python:
#!/bin/python3

import math
import os
import random
import re
import sys

# PART 1 - Implement Customer Register ADT

# Constructor
def makeCustomerRegister():
    return ("CR", [])

# Selector to get contents of the register
def contents(cr):
    if isCustomerRegister(cr):
        return cr[1]
    else:
        raise ValueError("Invalid Customer Register provided")

# Mutator to add a customer to the register
def addCustomer(custRec, cr):
    if isCustomerRegister(cr):
        cr[1].append(custRec)
    else:
        raise ValueError("Invalid Customer Register provided")

# Mutator to remove a customer from the register by their customer ID
def removeCustomer(cid, cr):
    if isCustomerRegister(cr):
        cr[1] = [record for record in cr[1] if record[0] != cid]
    else:
        raise ValueError("Invalid Customer Register provided")

# Predicate to check if an object is a valid Customer Register
def isCustomerRegister(cr):
    return isinstance(cr, tuple) and len(cr) == 2 and cr[0] == "CR" and isinstance(cr[1], list)

# Predicate to check if the Customer Register is empty
def isEmpty(cr):
    if isCustomerRegister(cr):
        return len(cr[1]) == 0
    else:
        raise ValueError("Invalid Customer Register provided")

# Part 2: Define Functions to Sign Up A New Customer

def generateCId(cName, cr, platinum=False):
    first_initial = cName[0][0].upper()
    last_initial = cName[1][0].upper()
    ascii_sum = ord(first_initial) + ord(last_initial)
    prefix = "PC" if platinum else "NC"
    cid = f"{prefix}{ascii_sum}"
    existing_cids = [cust[0] for cust in contents(cr)]
    while cid in existing_cids:
        ascii_sum += 1
        cid = f"{prefix}{ascii_sum}"
    return cid

def makeCustomerRecord(cid, hh, mm):
    return [
        cid,               # Customer ID
        (hh, mm),          # Arrival Time (HH, MM)
        -1,                # Service time (not assessed yet, so set to -1)
        []                 # Vehicle information (empty list, will be updated later)
    ]

# Update Functions
def updateVehicle(vhcl, custRec):
    custRec[3] = vhcl

def updateServiceTime(serviceTime, custRec):
    custRec[2] = serviceTime

def updateServiceCost(serviceCost, custRec):
    if custRec[3]:
        custRec[3][-1] = serviceCost

# Selector Functions for accessing customer record details
def getCID(custRec):
    return custRec[0]

def getArivalTime(custRec):
    hh, mm = custRec[1]
    return f"{hh:02}{mm:02}"

def getServiceTime(custRec):
    return custRec[2]

def getCustType(custRec):
    return "PC" if custRec[0].startswith("PC") else "NC"

def getVehicle(custRec):
    return custRec[3]

# Part 3: Adding Vehicle Information
def addVehicle(custReg, cid, pl, mk, md, y, ml, lsd):
    """
    Adds vehicle information to a customer record in the Customer Register.
    :param custReg: The existing Customer Register.
    :param cid: Customer ID to locate the record.
    :param pl: Pay Limit.
    :param mk: Make of the vehicle.
    :param md: Model of the vehicle.
    :param y: Year of the vehicle.
    :param ml: Mileage on the vehicle.
    :param lsd: Last service date in months.
    :return: Updates Customer Register with vehicle info added to the corresponding customer.
    """
    for custRec in contents(custReg):
        if getCID(custRec) == cid:
            vehicle_info = [pl, (mk, md, y), ml, lsd, 0]
            updateVehicle(vehicle_info, custRec)

# Main Program

if __name__ == '__main__':   
    no_of_customers = int(input())
    
    custReg = makeCustomerRegister()
    
    for i in range(no_of_customers):
        customer_info = input().strip().split(' ')
        
        if isCustomerRegister(custReg):
            # Check if the customer is Platinum based on the original ID
            platinum = customer_info[0][0] == "P"
            
            # Create the customer record directly using parsed information
            addCustomer(
                [
                    customer_info[0],
                    (int(customer_info[3]), int(customer_info[4])),
                    -1,
                    [
                        customer_info[5],
                        (customer_info[6], customer_info[7], customer_info[8]),
                        int(customer_info[9]),
                        customer_info[10],
                        0
                    ]
                ],
                custReg
            )
            
            # Use addVehicle to update the vehicle information, including adjusting mileage
            addVehicle(
                custReg,
                customer_info[0],
                customer_info[5],
                customer_info[6],
                customer_info[7],
                customer_info[8],
                int(customer_info[9]) + 5,  # Update mileage by adding 5
                customer_info[10]
            )
            
    # Print the remaining customers in the register
    for cust in contents(custReg):
        print(
            getCID(cust),
            getArivalTime(cust),
            getServiceTime(cust),
            getCustType(cust),
            getVehicle(cust)
        )
 
It sounds like you're finding the question tricky because the logic behind assessing the vehicle and calculating the costs can get complicated. Breaking it down piece by piece might help clarify things. Here’s a summary of the main steps needed:

  1. Check the vehicle's details like age, mileage, and the last service date to determine what kinds of repairs or checks are needed (full house check, tyre change, shocks test).
  2. Apply the service costs based on the vehicle's make and the type of service required. This comes from the servicing cost list, which holds prices for different makes and jobs.
  3. Check against the customer’s pay limit. If the total service cost goes beyond the customer’s budget by more than 5%, you’ll need to adjust by removing the least important or cheapest services until it's within the limit.
  4. Calculate the estimated pickup time by adding the total service time to the customer’s arrival time and subtracting 5 minutes.
It’s a complex problem, but once you break it down into these smaller steps, it becomes more manageable. Let me know if you want to talk through any specific part in more detail!
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom