Skip to content

Instantly share code, notes, and snippets.

@brandonhimpfen
Created April 24, 2026 03:45
Show Gist options
  • Select an option

  • Save brandonhimpfen/131117ed64a3630a3da376278f0de531 to your computer and use it in GitHub Desktop.

Select an option

Save brandonhimpfen/131117ed64a3630a3da376278f0de531 to your computer and use it in GitHub Desktop.
Python script that 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.
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 input.csv 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
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}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment