I draft custom cabinetry, and sometimes a run will need to be divided into say 3 cabinets, and I cannot have each cabinet section equal because the section width has to be imperial (to the 1/32") and cannot have a third of an inch. I generally have to do some rough math and adjust the widths as needed to maintain the total length of the run and maintaining imperial measurement, but I am writing a python program to calculate this for me. I will admit I am a hack at Python, but I am doing my best. This is what I have so far - how can 1) round each of the section widths to the nearest 1/32" while 2) maintaining the overall width? (i.e., not rounding all to the nearest because it may throw off the overall width) Thank you!
import math
# input total length of run
run_length = float(input("Enter length of the run, in inches:"))
# accounting for 1/8" reveals
reveal_num = float(input("Enter number of reveals: "))
reveal_length = reveal_num * 0.125
true_length = run_length - reveal_length
# determining number of run sections
section_num = float(input("Enter desired number of doors/sections: "))
# This is where the fun begins
# First group is nicely divisible into whole numbers
if true_length % section_num == 0:
section_length = true_length / section_num
print("Each section will be", section_length, "inches")
# Second group is divisible by 32nds, tested by multiplying by 32 and seeing if result is a
whole number
# Then to be rounded to the nearest 1/32" while maintaining the total width
elif ((true_length / section_num) * 32).is_integer():
# Third group is the misfits. Must be divided to the nearest 1/32" while maintaining the total
width.
else: