python code

I need simple code and report


def getData():
    customerData = []
    # Loop to get the data
    while (True):
        # List to store the data of current customer
        current_customer = []
        # Taking the inputs
        c_code = str(input(‘What is the rental code? Please choose B, D or W: ‘))
        c_name = str(input(“What is the customer’s name? “))
        mileage_start = float(input(“What is the mileage at the beginning? “))
        mileage_end = float(input(“What is the mileage at the end? “))
        days = int(input(‘How many days? ‘))
        # We added an “invalid” statement, incase the customer entered a wrong input
        if (mileage_end – mileage_start) < 0:
            print(‘Input invalid, End mileage cannot be smaller than start mileage.’)
            print(‘Input discarded, please enter again the customer information again with correct information’)
            continue
        # Adding the values to the list
        # Array is like this :  [Code, Name, Mileage_start, Mileage_end, Days]
        current_customer.append(c_code)
        current_customer.append(c_name)
        current_customer.append(mileage_start)
        current_customer.append(mileage_end)
        current_customer.append(days)
        # Adding the list of customer data to the multi-dimensional list
        customerData.append(current_customer)
        # Ask to enter data or not
        decision = str(input(“Would you like to add another customer? Enter ‘Y’ for yes or ‘Q’ for quit: “))
        # If ‘Y’ or ‘y’, do nothing and ask again, if ‘Q’ or ‘q’, quit from taking input, if any other character, show error and quit
        if (decision == ‘Q’ or decision == ‘q’):
            break
        elif (decision == ‘Y’ or decision == ‘y’):
            continue
        else:
            print(‘Invalid input, returning the customer information. No more information allowed to enter’)
            break
    # Return the customer data
    return customerData
def calculateBill(c_data):
    code = c_data[0]
    n_days = c_data[4]
    m_start = c_data[2]
    m_end = c_data[3]
    name = c_data[1]
    # We calculate Kilometer driven based on the classification code
    km_driven = round((m_end – m_start), 1)
    average_km = km_driven / n_days
    m_charge = 0
    # We calculate the miles charged for Classification code “B”:
    if code == ‘B’ or code == ‘b’:
        b_charge = 40 * n_days
        m_charge = 0.25 * km_driven
    # We calculate the miles charged for Classification code “D”:
    elif code == ‘D’ or code == ‘d’:
        b_charge = 60 * n_days
        average_km = km_driven / n_days
        if (average_km > 100):
            extra_km = average_km – 100
            m_charge = 0.25 * extra_km
    # We calculate the miles charged for Classification code “W”:
    elif code == ‘W’ or code == ‘w’:
        n_weeks = n_days / 7
        if (n_weeks % 7 != 0):
            n_weeks = int(n_weeks) + 1
        average_km = km_driven / n_weeks
        b_charge = 190 * n_weeks
        if (average_km > 900 and average_km < 1500):
            m_charge = 100 * n_weeks
        elif (average_km > 1500):
            extra_km = average_km – 1500
            m_charge = (200 * n_weeks) + (0.25 * extra_km)
    else:
        b_charge = 0
    total_charge = round((b_charge + m_charge), 2)
    return total_charge, km_driven
# We greet the customer’s and asking them to enter their details in order to calcualte the bill
def main():
    print(‘WELCOME TO CAR RENTAL ACCOUNTING SYSTEM!’)
    print(‘You will be prompted to enter details to calculate the bills. ‘)
    print(‘——————————————————————-\n’)
    customerData = getData()
    # We created a file under the name “Summary” which will include all the information about the customer’s car rental
    f = open(“summary.txt”, “w”)
    f.write(‘Summary for rental system\n’)
    f.write(‘———————————————\n’)
    print(‘\n———————————————————–\n’)
    # We add the informations,in order, into the file
    for i in range(len(customerData)):
        current_customer = customerData[i]
        total_bill, total_km = calculateBill(current_customer)
        f.write(‘Classification code: ‘ + str(current_customer[0]) + ‘\n’)
        f.write(‘Customer Name: ‘ + str(current_customer[1]) + ‘\n’)
        f.write(‘Number of days: ‘ + str(current_customer[4]) + ‘\n’)
        f.write(“Mileage at start: ” + str(float(current_customer[2])) + ‘\n’)
        f.write(“Mileage at end: ” + str(float(current_customer[3])) + ‘\n’)
        f.write(“Number of kilometers driven: ” + str(float(total_km)) + ‘\n’)
        f.write(“Amount due: $” + str(total_bill) + ‘\n’)
        f.write(‘———————————————‘ + ‘\n\n’)
    # We inform the customer that all the details have been saved in the file
    print(‘Data Saved to summary file’)
    print(‘Program will exit now!’)
    print(‘——————————————————————‘)
if __name__ == ‘__main__’:
    main()

Leave a Reply

Your email address will not be published. Required fields are marked *