Calculate the Selling Price of Multiple Photography Prints using Python

In a previous post, I showed you a Python script that will allow you to determine the price of a print using the command line. But, how about if you have multiple photography prints? No problem.

Calculate the Selling Price of Multiple Photography Prints using Python
Photo by Angèle Kamp / Unsplash

In a previous post, I showed you a Python script that will allow you to determine the price of a photography print using the command line. But, how about if you have multiple photography prints that you want to determine the price for? No problem. You may use the following Python script, which will allow you to add multiple photography prints in a CSV file and will output another CSV file with the price of each photography print.

import csv

# Define the formula function
def calculate_print_price(size, edition, reputation_factor, production_cost, framing_cost, subject_value):
    type_factor = 1.0
    if size == 16:
        type_factor = 1.0
    elif size == 20:
        type_factor = 1.5
    elif size == 24:
        type_factor = 2.0
    else:
        print(f"Error: invalid size '{size}'")
        return None
    
    total_cost = production_cost + framing_cost
    subject_value_multiplier = 1.0 + (subject_value / 10)
    
    return round(type_factor * edition * reputation_factor * total_cost * subject_value_multiplier, 2)

# Define the input and output file paths
input_file_path = 'input.csv'
output_file_path = 'output.csv'

# Read the input CSV file
with open(input_file_path, mode='r') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    input_rows = list(csv_reader)

# Calculate the print price for each row
for row in input_rows:
    size = int(row['Size'])
    edition = int(row['Edition'])
    reputation_factor = float(row['Reputation Factor'])
    production_cost = float(row['Production Cost'])
    framing_cost = float(row['Framing Cost'])
    subject_value = float(row['Subject Value'])
    
    print_price = calculate_print_price(size, edition, reputation_factor, production_cost, framing_cost, subject_value)
    if print_price is not None:
        row['Print Price'] = print_price

# Write the results to the output CSV file
with open(output_file_path, mode='w', newline='') as csv_file:
    field_names = input_rows[0].keys()
    csv_writer = csv.DictWriter(csv_file, fieldnames=field_names)
    csv_writer.writeheader()
    csv_writer.writerows(input_rows)

print(f"Results written to {output_file_path}")

Here is an example input.csv file:

Size,Edition,Reputation Factor,Production Cost,Framing Cost,Subject Value
16,50,1.5,200,200,0
20,100,1.2,300,250,1.5
24,25,1.8,350,300,-0.5

The script will read the input values from the CSV file to calculate the print price and write the results to the output.csv file with an additional 'Print Price' column. Here is an example of how the output.csv would look like:

Size,Edition,Reputation Factor,Production Cost,Framing Cost,Subject Value,Print Price
16,50,1.5,200,200,0,840.8
20,100,1.2,300,250,1.5,3150.0
24,25,1.8,350,300,-0.5,3187.5

Enjoy! Hope you found this script useful.