6
\$\begingroup\$

I'm new to coding but I'm particularly new to python. I wrote a program that will determine a diver's table and schedule(because it relates to my job). It essentially assigns a value from multiple lists based on a given int(bottom time), and another given int(depth) as well as a given string associated with those to ints. I spent a lot of time typing this all out and I couldn't help but think there's probably a better way to do this. I'm hoping you can help me.

#This program is intended for No-Decompression dives. Do not use for decompression
# or repet dives!
#final bottom time
fbt = 0
#final max depth
fmd = 0
print("WARNING! This program will not properly compute decompression or exceptional exposure dives!")
#prompts the user to enter the max depth and bottom time of the dive
md = int(input("What is the max depth of the dive in feet? "))
bt = int(input("What is the total bottom time of the dive in minutes? "))
repet_des = "A"
#lists of tables/depths/repet designators
repet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "Z"]
depths = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]
ten_fsw = [57 , 101, 158, 245, 426]
fifteen_fsw = [36, 60, 88, 121, 163, 271, 297, 449]
twenty_fsw = [26, 43, 61, 82, 106, 133, 165, 205, 256, 330, 416]
twenty_five_fsw = [20, 33, 47, 62, 78, 97, 117, 140, 166, 198, 236, 285, 354, 469, 992, 1102]
thirty_fsw = [17, 27, 38, 50, 62, 76, 91, 107, 125, 145, 167, 193, 223, 260, 307, 371]
thirty_five_fsw = [14, 23, 32, 42, 52, 63, 74, 87, 100, 115, 131, 148, 168, 190, 215, 232]
fourty_fsw = [12, 20, 27, 36, 44, 53, 63, 73, 84, 95, 108, 121, 135, 151, 163]
fourty_five_fsw = [11, 17, 24, 31, 39, 46, 55, 63, 72, 82, 92, 102, 114, 125]
fifty_fsw = [9, 15, 21, 28, 34, 41, 48, 56, 63, 71, 80, 89, 92]
fifty_five_fsw = [8, 14, 19, 25, 31, 37, 43, 50, 56, 63, 71, 74]
sixty_fsw = [7, 12, 17, 22, 28, 33, 39, 45, 51, 57, 63]
seventy_fsw = [6, 10, 14, 19, 23, 28, 32, 37, 42, 47, 4]
eighty_fsw = [5, 9, 12, 16, 20, 24, 28, 32, 36, 39]
ninety_fsw = [4, 7, 11, 14, 17, 21, 24, 28, 31, 33]
one_hundred_fsw = [4, 6, 9, 12, 15, 18, 21, 2]
one_hundred_ten_fsw = [3, 6, 8, 11, 14, 16, 19, 20]
one_hundred_twenty_fsw = [3, 5, 7, 10, 12, 15]
one_hundred_thirty_fsw = [2, 4, 6, 9, 11, 12]
one_hundred_fourty_fsw = [2, 4, 6, 8, 10]
one_hundred_fifty_fsw = [3, 5, 7, 8]
one_hundred_sixty_fsw = [3, 5, 6, 7]
one_hundred_seventy_fsw = [4, 6]
one_hundred_eighty_fsw = [4, 5, 6]
one_hundred_ninety_fsw = [3, 5]
#Calculates T/S if MD is 10 or less.
if md <= depths[0]:
 fmd = depths[0]
 if bt <= ten_fsw[0]:
 fbt = ten_fsw[0]
 repet_des = repet[0]
 elif bt > ten_fsw[0] and bt <= ten_fsw[1]:
 fbt = ten_fsw[1]
 repet_des = repet[1]
 elif bt > ten_fsw[1] and bt <= ten_fsw[2]:
 fbt = ten_fsw[2]
 repet_des = repet[2]
 elif bt > ten_fsw[2] and bt <= ten_fsw[3]:
 fbt = ten_fsw[3]
 repet_des = repet[3]
 elif bt > ten_fsw[3]:
 fbt = ten_fsw[4]
 repet_des = repet[4]
#Calculates T/S if MD is 15 or less.
elif md <= depths[1]:
 fmd = depths[1]
 if bt <= fifteen_fsw[0]:
 fbt = fifteen_fsw[0]
 repet_des = repet[0]
 elif bt > fifteen_fsw[0] and bt <= fifteen_fsw[1]:
 fbt = fifteen_fsw[1]
 repet_des = repet[1]
 elif bt > fifteen_fsw[1] and bt <= fifteen_fsw[2]:
 fbt = fifteen_fsw[2]
 repet_des = repet[2]
 elif bt > fifteen_fsw[2] and bt <= fifteen_fsw[3]:
 fbt = fifteen_fsw[3]
 repet_des = repet[3]
 elif bt > fifteen_fsw[3] and bt <= fifteen_fsw[4]:
 fbt = fifteen_fsw[4]
 repet_des = repet[4]
 elif bt > fifteen_fsw[4] and bt <= fifteen_fsw[5]:
 fbt = fifteen_fsw[5]
 repet_des = repet[5]
 elif bt > fifteen_fsw[5] and bt <= fifteen_fsw[6]:
 fbt = fifteen_fsw[6]
 repet_des = repet[6]
 elif bt > fifteen_fsw[6]:
 fbt = fifteen_fsw[7]
 repet_des = repet[7]
#Calculates T/S if MD is 20 or less.
elif md <= depths[2]:
 fmd = depths[2]
 if bt <= twenty_fsw[0]:
 fbt = twenty_fsw[0]
 repet_des = repet[0]
 elif bt > twenty_fsw[0] and bt <= twenty_fsw[1]:
 fbt = twenty_fsw[1]
 repet_des = repet[1]
 elif bt > twenty_fsw[1] and bt <= twenty_fsw[2]:
 fbt = twenty_fsw[2]
 repet_des = repet[2]
 elif bt > twenty_fsw[2] and bt <= twenty_fsw[3]:
 fbt = twenty_fsw[3]
 repet_des = repet[3]
 elif bt > twenty_fsw[3] and bt <= twenty_fsw[4]:
 fbt = twenty_fsw[4]
 repet_des = repet[4]
 elif bt > twenty_fsw[4] and bt <= twenty_fsw[5]:
 fbt = twenty_fsw[5]
 repet_des = repet[5]
 elif bt > twenty_fsw[5] and bt <= twenty_fsw[6]:
 fbt = twenty_fsw[6]
 repet_des = repet[6]
 elif bt > twenty_fsw[6] and bt <= twenty_fsw[7]:
 fbt = twenty_fsw[7]
 repet_des = repet[7]
 elif bt > twenty_fsw[7] and bt <= twenty_fsw[8]:
 fbt = twenty_fsw[8]
 repet_des = repet[8]
 elif bt > twenty_fsw[8] and bt <= twenty_fsw[9]:
 fbt = twenty_fsw[9]
 repet_des = repet[9]
 elif bt > twenty_fsw[9]:
 fbt = twenty_fsw[10]
 repet_des = repet[10]
#Calculates T/S if MD is 25 or less.
elif md <= depths[3]:
 fmd = depths[3]
 if bt <= twenty_five_fsw[0]:
 fbt = twenty_five_fsw[0]
 repet_des = repet[0]
 elif bt > twenty_five_fsw[0] and bt <= twenty_five_fsw[1]:
 fbt = twenty_five_fsw[1]
 repet_des = repet[1]
 elif bt > twenty_five_fsw[1] and bt <= twenty_five_fsw[2]:
 fbt = twenty_five_fsw[2]
 repet_des = repet[2]
 elif bt > twenty_five_fsw[2] and bt <= twenty_five_fsw[3]:
 fbt = twenty_five_fsw[3]
 repet_des = repet[3]
 elif bt > twenty_five_fsw[3] and bt <= twenty_five_fsw[4]:
 fbt = twenty_five_fsw[4]
 repet_des = repet[4]
 elif bt > twenty_five_fsw[4] and bt <= twenty_five_fsw[5]:
 fbt = twenty_five_fsw[5]
 repet_des = repet[5]
 elif bt > twenty_five_fsw[5] and bt <= twenty_five_fsw[6]:
 fbt = twenty_five_fsw[6]
 repet_des = repet[6]
 elif bt > twenty_five_fsw[6] and bt <= twenty_five_fsw[7]:
 fbt = twenty_five_fsw[7]
 repet_des = repet[7]
 elif bt > twenty_five_fsw[7] and bt <= twenty_five_fsw[8]:
 fbt = twenty_five_fsw[8]
 repet_des = repet[8]
 elif bt > twenty_five_fsw[8] and bt <= twenty_five_fsw[9]:
 fbt = twenty_five_fsw[9]
 repet_des = repet[9]
 elif bt > twenty_five_fsw[9] and bt <= twenty_five_fsw[10]:
 fbt = twenty_five_fsw[10]
 repet_des = repet[10]
 elif bt > twenty_five_fsw[10] and bt <= twenty_five_fsw[11]:
 fbt = twenty_five_fsw[11]
 repet_des = repet[11]
 elif bt > twenty_five_fsw[11] and bt <= twenty_five_fsw[12]:
 fbt = twenty_five_fsw[12]
 repet_des = repet[12]
 elif bt > twenty_five_fsw[12] and bt <= twenty_five_fsw[13]:
 fbt = twenty_five_fsw[13]
 repet_des = repet[13]
 elif bt > twenty_five_fsw[13] and bt <= twenty_five_fsw[14]:
 fbt = twenty_five_fsw[14]
 repet_des = repet[14]
 elif bt > twenty_five_fsw[14]:
 fbt = twenty_five_fsw[15]
 repet_des = repet[15]
elif md <= depths[4]:
 fmd = depths[4]
 if bt <= thirty_fsw[0]:
 fbt = thirty_fsw[0]
 repet_des = repet[0]
 elif bt > thirty_fsw[0] and bt <= thirty_fsw[1]:
 fbt = thirty_fsw[1]
 repet_des = repet[1]
 elif bt > thirty_fsw[1] and bt <= thirty_fsw[2]:
 fbt = thirty_fsw[2]
 repet_des = repet[2]
 elif bt > thirty_fsw[2] and bt <= thirty_fsw[3]:
 fbt = thirty_fsw[3]
 repet_des = repet[3]
 elif bt > thirty_fsw[3] and bt <= thirty_fsw[4]:
 fbt = thirty_fsw[4]
 repet_des = repet[4]
 elif bt > thirty_fsw[4] and bt <= thirty_fsw[5]:
 fbt = thirty_fsw[5]
 repet_des = repet[5]
 elif bt > thirty_fsw[5] and bt <= thirty_fsw[6]:
 fbt = thirty_fsw[6]
 repet_des = repet[6]
 elif bt > thirty_fsw[6] and bt <= thirty_fsw[7]:
 fbt = thirty_fsw[7]
 repet_des = repet[7]
 elif bt > thirty_fsw[7] and bt <= thirty_fsw[8]:
 fbt = thirty_fsw[8]
 repet_des = repet[8]
 elif bt > thirty_fsw[8] and bt <= thirty_fsw[9]:
 fbt = thirty_fsw[9]
 repet_des = repet[9]
 elif bt > thirty_fsw[9] and bt <= thirty_fsw[10]:
 fbt = thirty_fsw[10]
 repet_des = repet[10]
 elif bt > thirty_fsw[10] and bt <= thirty_fsw[11]:
 fbt = thirty_fsw[11]
 repet_des = repet[11]
 elif bt > thirty_fsw[11] and bt <= thirty_fsw[12]:
 fbt = thirty_fsw[12]
 repet_des = repet[12]
 elif bt > thirty_fsw[12] and bt <= thirty_fsw[13]:
 fbt = thirty_fsw[13]
 repet_des = repet[13]
 elif bt > thirty_fsw[13] and bt <= thirty_fsw[14]:
 fbt = thirty_fsw[14]
 repet_des = repet[14]
 elif bt > thirty_fsw[14]:
 fbt = thirty_fsw[15]
 repet_des = repet[15]
#Calculates T/S if MD is 35 or less.
elif md <= depths[5]:
 fmd = depths[5]
 if bt <= thirty_five_fsw[0]:
 fbt = thirty_five_fsw[0]
 repet_des = repet[0]
 elif bt > thirty_five_fsw[0] and bt <= thirty_five_fsw[1]:
 fbt = thirty_five_fsw[1]
 repet_des = repet[1]
 elif bt > thirty_five_fsw[1] and bt <= thirty_five_fsw[2]:
 fbt = thirty_five_fsw[2]
 repet_des = repet[2]
 elif bt > thirty_five_fsw[2] and bt <= thirty_five_fsw[3]:
 fbt = thirty_five_fsw[3]
 repet_des = repet[3]
 elif bt > thirty_five_fsw[3] and bt <= thirty_five_fsw[4]:
 fbt = thirty_five_fsw[4]
 repet_des = repet[4]
 elif bt > thirty_five_fsw[4] and bt <= thirty_five_fsw[5]:
 fbt = thirty_five_fsw[5]
 repet_des = repet[5]
 elif bt > thirty_five_fsw[5] and bt <= thirty_five_fsw[6]:
 fbt = thirty_five_fsw[6]
 repet_des = repet[6]
 elif bt > thirty_five_fsw[6] and bt <= thirty_five_fsw[7]:
 fbt = thirty_five_fsw[7]
 repet_des = repet[7]
 elif bt > thirty_five_fsw[7] and bt <= thirty_five_fsw[8]:
 fbt = thirty_five_fsw[8]
 repet_des = repet[8]
 elif bt > thirty_five_fsw[8] and bt <= thirty_five_fsw[9]:
 fbt = thirty_five_fsw[9]
 repet_des = repet[9]
 elif bt > thirty_five_fsw[9] and bt <= thirty_five_fsw[10]:
 fbt = thirty_five_fsw[10]
 repet_des = repet[10]
 elif bt > thirty_five_fsw[10] and bt <= thirty_five_fsw[11]:
 fbt = thirty_five_fsw[11]
 repet_des = repet[11]
 elif bt > thirty_five_fsw[11] and bt <= thirty_five_fsw[12]:
 fbt = thirty_five_fsw[12]
 repet_des = repet[12]
 elif bt > thirty_five_fsw[12] and bt <= thirty_five_fsw[13]:
 fbt = thirty_five_fsw[13]
 repet_des = repet[13]
 elif bt > thirty_five_fsw[13] and bt <= thirty_five_fsw[14]:
 fbt = thirty_five_fsw[14]
 repet_des = repet[14]
 elif bt > thirty_five_fsw[14]:
 fbt = thirty_five_fsw[15]
 repet_des = repet[15]
#Calculates T/S if MD is 40 or less.
elif md <= depths[6]:
 fmd = depths[6]
 if bt <= fourty_fsw[0]:
 fbt = fourty_fsw[0]
 repet_des = repet[0]
 elif bt > fourty_fsw[0] and bt <= fourty_fsw[1]:
 fbt = fourty_fsw[1]
 repet_des = repet[1]
 elif bt > fourty_fsw[1] and bt <= fourty_fsw[2]:
 fbt = fourty_fsw[2]
 repet_des = repet[2]
 elif bt > fourty_fsw[2] and bt <= fourty_fsw[3]:
 fbt = fourty_fsw[3]
 repet_des = repet[3]
 elif bt > fourty_fsw[3] and bt <= fourty_fsw[4]:
 fbt = fourty_fsw[4]
 repet_des = repet[4]
 elif bt > fourty_fsw[4] and bt <= fourty_fsw[5]:
 fbt = fourty_fsw[5]
 repet_des = repet[5]
 elif bt > fourty_fsw[5] and bt <= fourty_fsw[6]:
 fbt = fourty_fsw[6]
 repet_des = repet[6]
 elif bt > fourty_fsw[6] and bt <= fourty_fsw[7]:
 fbt = fourty_fsw[7]
 repet_des = repet[7]
 elif bt > fourty_fsw[7] and bt <= fourty_fsw[8]:
 fbt = fourty_fsw[8]
 repet_des = repet[8]
 elif bt > fourty_fsw[8] and bt <= fourty_fsw[9]:
 fbt = fourty_fsw[9]
 repet_des = repet[9]
 elif bt > fourty_fsw[9] and bt <= fourty_fsw[10]:
 fbt = fourty_fsw[10]
 repet_des = repet[10]
 elif bt > fourty_fsw[10] and bt <= fourty_fsw[11]:
 fbt = fourty_fsw[11]
 repet_des = repet[11]
 elif bt > fourty_fsw[11] and bt <= fourty_fsw[12]:
 fbt = fourty_fsw[12]
 repet_des = repet[12]
 elif bt > fourty_fsw[12] and bt <= fourty_fsw[13]:
 fbt = fourty_fsw[13]
 repet_des = repet[13]
 elif bt > fourty_fsw[13]:
 fbt = fourty_fsw[14]
 repet_des = repet[14]
#Calculates T/S if MD is 45 or less.
elif md <= depths[7]:
 fmd = depths[7]
 if bt <= fourty_five_fsw[0]:
 fbt = fourty_five_fsw[0]
 repet_des = repet[0]
 elif bt > fourty_five_fsw[0] and bt <= fourty_five_fsw[1]:
 fbt = fourty_five_fsw[1]
 repet_des = repet[1]
 elif bt > fourty_five_fsw[1] and bt <= fourty_five_fsw[2]:
 fbt = fourty_five_fsw[2]
 repet_des = repet[2]
 elif bt > fourty_five_fsw[2] and bt <= fourty_five_fsw[3]:
 fbt = fourty_five_fsw[3]
 repet_des = repet[3]
 elif bt > fourty_five_fsw[3] and bt <= fourty_five_fsw[4]:
 fbt = fourty_five_fsw[4]
 repet_des = repet[4]
 elif bt > fourty_five_fsw[4] and bt <= fourty_five_fsw[5]:
 fbt = fourty_five_fsw[5]
 repet_des = repet[5]
 elif bt > fourty_five_fsw[5] and bt <= fourty_five_fsw[6]:
 fbt = fourty_five_fsw[6]
 repet_des = repet[6]
 elif bt > fourty_five_fsw[6] and bt <= fourty_five_fsw[7]:
 fbt = fourty_five_fsw[7]
 repet_des = repet[7]
 elif bt > fourty_five_fsw[7] and bt <= fourty_five_fsw[8]:
 fbt = fourty_five_fsw[8]
 repet_des = repet[8]
 elif bt > fourty_five_fsw[8] and bt <= fourty_five_fsw[9]:
 fbt = fourty_five_fsw[9]
 repet_des = repet[9]
 elif bt > fourty_five_fsw[9] and bt <= fourty_five_fsw[10]:
 fbt = fourty_five_fsw[10]
 repet_des = repet[10]
 elif bt > fourty_five_fsw[10] and bt <= fourty_five_fsw[11]:
 fbt = fourty_five_fsw[11]
 repet_des = repet[11]
 elif bt > fourty_five_fsw[11] and bt <= fourty_five_fsw[12]:
 fbt = fourty_five_fsw[12]
 repet_des = repet[12]
 elif bt > fourty_five_fsw[12]:
 fbt = fourty_five_fsw[13]
 repet_des = repet[13]
#Calculates T/S if MD is 50 or less.
elif md <= depths[8]:
 fmd = depths[8]
 if bt <= fifty_fsw[0]:
 fbt = fifty_fsw[0]
 repet_des = repet[0]
 elif bt > fifty_fsw[0] and bt <= fifty_fsw[1]:
 fbt = fifty_fsw[1]
 repet_des = repet[1]
 elif bt > fifty_fsw[1] and bt <= fifty_fsw[2]:
 fbt = fifty_fsw[2]
 repet_des = repet[2]
 elif bt > fifty_fsw[2] and bt <= fifty_fsw[3]:
 fbt = fifty_fsw[3]
 repet_des = repet[3]
 elif bt > fifty_fsw[3] and bt <= fifty_fsw[4]:
 fbt = fifty_fsw[4]
 repet_des = repet[4]
 elif bt > fifty_fsw[4] and bt <= fifty_fsw[5]:
 fbt = fifty_fsw[5]
 repet_des = repet[5]
 elif bt > fifty_fsw[5] and bt <= fifty_fsw[6]:
 fbt = fifty_fsw[6]
 repet_des = repet[6]
 elif bt > fifty_fsw[6] and bt <= fifty_fsw[7]:
 fbt = fifty_fsw[7]
 repet_des = repet[7]
 elif bt > fifty_fsw[7] and bt <= fifty_fsw[8]:
 fbt = fifty_fsw[8]
 repet_des = repet[8]
 elif bt > fifty_fsw[8] and bt <= fifty_fsw[9]:
 fbt = fifty_fsw[9]
 repet_des = repet[9]
 elif bt > fifty_fsw[9] and bt <= fifty_fsw[10]:
 fbt = fifty_fsw[10]
 repet_des = repet[10]
 elif bt > fifty_fsw[10] and bt <= fifty_fsw[11]:
 fbt = fifty_fsw[11]
 repet_des = repet[11]
 elif bt > fifty_fsw[11]:
 fbt = fifty_fsw[12]
 repet_des = repet[12]
#Calculates T/S if MD is 55 or less.
elif md <= depths[9]:
 fmd = depths[10]
 if bt <= fifty_five_fsw[0]:
 fbt = fifty_five_fsw[0]
 repet_des = repet[0]
 elif bt > fifty_five_fsw[0] and bt <= fifty_five_fsw[1]:
 fbt = fifty_five_fsw[1]
 repet_des = repet[1]
 elif bt > fifty_five_fsw[1] and bt <= fifty_five_fsw[2]:
 fbt = fifty_five_fsw[2]
 repet_des = repet[2]
 elif bt > fifty_five_fsw[2] and bt <= fifty_five_fsw[3]:
 fbt = fifty_five_fsw[3]
 repet_des = repet[3]
 elif bt > fifty_five_fsw[3] and bt <= fifty_five_fsw[4]:
 fbt = fifty_five_fsw[4]
 repet_des = repet[4]
 elif bt > fifty_five_fsw[4] and bt <= fifty_five_fsw[5]:
 fbt = fifty_five_fsw[5]
 repet_des = repet[5]
 elif bt > fifty_five_fsw[5] and bt <= fifty_five_fsw[6]:
 fbt = fifty_five_fsw[6]
 repet_des = repet[6]
 elif bt > fifty_five_fsw[6] and bt <= fifty_five_fsw[7]:
 fbt = fifty_five_fsw[7]
 repet_des = repet[7]
 elif bt > fifty_five_fsw[7] and bt <= fifty_five_fsw[8]:
 fbt = fifty_five_fsw[8]
 repet_des = repet[8]
 elif bt > fifty_five_fsw[8] and bt <= fifty_five_fsw[9]:
 fbt = fifty_five_fsw[9]
 repet_des = repet[9]
 elif bt > fifty_five_fsw[9] and bt <= fifty_five_fsw[10]:
 fbt = fifty_five_fsw[10]
 repet_des = repet[10]
 elif bt > fifty_five_fsw[10]:
 fbt = fifty_five_fsw[11]
 repet_des = repet[11]
#Calculates T/S if MD is 60 or less.
elif md <= depths[10]:
 fmd = depths[11]
 if bt <= sixty_fsw[0]:
 fbt = sixty_fsw[0]
 repet_des = repet[0]
 elif bt > sixty_fsw[0] and bt <= sixty_fsw[1]:
 fbt = sixty_fsw[1]
 repet_des = repet[1]
 elif bt > sixty_fsw[1] and bt <= sixty_fsw[2]:
 fbt = sixty_fsw[2]
 repet_des = repet[2]
 elif bt > sixty_fsw[2] and bt <= sixty_fsw[3]:
 fbt = sixty_fsw[3]
 repet_des = repet[3]
 elif bt > sixty_fsw[3] and bt <= sixty_fsw[4]:
 fbt = sixty_fsw[4]
 repet_des = repet[4]
 elif bt > sixty_fsw[4] and bt <= sixty_fsw[5]:
 fbt = sixty_fsw[5]
 repet_des = repet[5]
 elif bt > sixty_fsw[5] and bt <= sixty_fsw[6]:
 fbt = sixty_fsw[6]
 repet_des = repet[6]
 elif bt > sixty_fsw[6] and bt <= sixty_fsw[7]:
 fbt = sixty_fsw[7]
 repet_des = repet[7]
 elif bt > sixty_fsw[7] and bt <= sixty_fsw[8]:
 fbt = sixty_fsw[8]
 repet_des = repet[8]
 elif bt > sixty_fsw[8] and bt <= sixty_fsw[9]:
 fbt = sixty_fsw[9]
 repet_des = repet[9]
 elif bt > sixty_fsw[9]:
 fbt = sixty_fsw[10]
 repet_des = repet[10]
#Calculates T/S if MD is 70 or less.
elif md <= depths[11]:
 fmd = depths[12]
 if bt <= seventy_fsw[0]:
 fbt = seventy_fsw[0]
 repet_des = repet[0]
 elif bt > seventy_fsw[0] and bt <= seventy_fsw[1]:
 fbt = seventy_fsw[1]
 repet_des = repet[1]
 elif bt > seventy_fsw[1] and bt <= seventy_fsw[2]:
 fbt = seventy_fsw[2]
 repet_des = repet[2]
 elif bt > seventy_fsw[2] and bt <= seventy_fsw[3]:
 fbt = seventy_fsw[3]
 repet_des = repet[3]
 elif bt > seventy_fsw[3] and bt <= seventy_fsw[4]:
 fbt = seventy_fsw[4]
 repet_des = repet[4]
 elif bt > seventy_fsw[4] and bt <= seventy_fsw[5]:
 fbt = seventy_fsw[5]
 repet_des = repet[5]
 elif bt > seventy_fsw[5] and bt <= seventy_fsw[6]:
 fbt = seventy_fsw[6]
 repet_des = repet[6]
 elif bt > seventy_fsw[6] and bt <= seventy_fsw[7]:
 fbt = seventy_fsw[7]
 repet_des = repet[7]
 elif bt > seventy_fsw[7] and bt <= seventy_fsw[8]:
 fbt = seventy_fsw[8]
 repet_des = repet[8]
 elif bt > seventy_fsw[8] and bt <= seventy_fsw[9]:
 fbt = seventy_fsw[9]
 repet_des = repet[9]
 elif bt > seventy_fsw[9]:
 fbt = seventy_fsw[10]
 repet_des = repet[10]
##Calculates T/S if MD is 80 or less.
elif md <= depths[12]:
 fmd = depths[12]
 if bt <= eighty_fsw[0]:
 fbt = eighty_fsw[0]
 repet_des = repet[0]
 elif bt > eighty_fsw[0] and bt <= eighty_fsw[1]:
 fbt = eighty_fsw[1]
 repet_des = repet[1]
 elif bt > eighty_fsw[1] and bt <= eighty_fsw[2]:
 fbt = eighty_fsw[2]
 repet_des = repet[2]
 elif bt > eighty_fsw[2] and bt <= eighty_fsw[3]:
 fbt = eighty_fsw[3]
 repet_des = repet[3]
 elif bt > eighty_fsw[3] and bt <= eighty_fsw[4]:
 fbt = eighty_fsw[4]
 repet_des = repet[4]
 elif bt > eighty_fsw[4] and bt <= eighty_fsw[5]:
 fbt = eighty_fsw[5]
 repet_des = repet[5]
 elif bt > eighty_fsw[5] and bt <= eighty_fsw[6]:
 fbt = eighty_fsw[6]
 repet_des = repet[6]
 elif bt > eighty_fsw[6] and bt <= eighty_fsw[7]:
 fbt = eighty_fsw[7]
 repet_des = repet[7]
 elif bt > eighty_fsw[7] and bt <= eighty_fsw[8]:
 fbt = eighty_fsw[8]
 repet_des = repet[8]
 elif bt > eighty_fsw[8]:
 fbt = eighty_fsw[9]
 repet_des = repet[9]
##Calculates T/S if MD is 90 or less.
elif md <= depths[13]:
 fmd = depths[13]
 if bt <= ninety_fsw[0]:
 fbt = ninety_fsw[0]
 repet_des = repet[0]
 elif bt > ninety_fsw[0] and bt <= ninety_fsw[1]:
 fbt = ninety_fsw[1]
 repet_des = repet[1]
 elif bt > ninety_fsw[1] and bt <= ninety_fsw[2]:
 fbt = ninety_fsw[2]
 repet_des = repet[2]
 elif bt > ninety_fsw[2] and bt <= ninety_fsw[3]:
 fbt = ninety_fsw[3]
 repet_des = repet[3]
 elif bt > ninety_fsw[3] and bt <= ninety_fsw[4]:
 fbt = ninety_fsw[4]
 repet_des = repet[4]
 elif bt > ninety_fsw[4] and bt <= ninety_fsw[5]:
 fbt = ninety_fsw[5]
 repet_des = repet[5]
 elif bt > ninety_fsw[5] and bt <= ninety_fsw[6]:
 fbt = ninety_fsw[6]
 repet_des = repet[6]
 elif bt > ninety_fsw[6] and bt <= ninety_fsw[7]:
 fbt = ninety_fsw[7]
 repet_des = repet[7]
 elif bt > ninety_fsw[7] and bt <= ninety_fsw[8]:
 fbt = ninety_fsw[8]
 repet_des = repet[8]
 elif bt > ninety_fsw[8]:
 fbt = ninety_fsw[9]
 repet_des = repet[9]
##Calculates T/S if MD is 100 or less.
elif md <= depths[14]:
 fmd = depths[14]
 if bt <= one_hundred_fsw[0]:
 fbt = one_hundred_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_fsw[0] and bt <= one_hundred_fsw[1]:
 fbt = one_hundred_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_fsw[1] and bt <= one_hundred_fsw[2]:
 fbt = one_hundred_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_fsw[2] and bt <= one_hundred_fsw[3]:
 fbt = one_hundred_fsw[3]
 repet_des = repet[3]
 elif bt > one_hundred_fsw[3] and bt <= one_hundred_fsw[4]:
 fbt = one_hundred_fsw[4]
 repet_des = repet[4]
 elif bt > one_hundred_fsw[4] and bt <= one_hundred_fsw[5]:
 fbt = one_hundred_fsw[5]
 repet_des = repet[5]
 elif bt > one_hundred_fsw[5] and bt <= one_hundred_fsw[6]:
 fbt = one_hundred_fsw[6]
 repet_des = repet[6]
 elif bt > one_hundred_fsw[6]:
 fbt = one_hundred_fsw[7]
 repet_des = repet[7]
 ##Calculates T/S if MD is 110 or less.
elif md <= depths[15]:
 fmd = depths[15]
 if bt <= one_hundred_ten_fsw[0]:
 fbt = one_hundred_ten_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_ten_fsw[0] and bt <= one_hundred_ten_fsw[1]:
 fbt = one_hundred_ten_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_ten_fsw[1] and bt <= one_hundred_ten_fsw[2]:
 fbt = one_hundred_ten_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_ten_fsw[2] and bt <= one_hundred_ten_fsw[3]:
 fbt = one_hundred_ten_fsw[3]
 repet_des = repet[3]
 elif bt > one_hundred_ten_fsw[3] and bt <= one_hundred_ten_fsw[4]:
 fbt = one_hundred_ten_fsw[4]
 repet_des = repet[4]
 elif bt > one_hundred_ten_fsw[4] and bt <= one_hundred_ten_fsw[5]:
 fbt = one_hundred_ten_fsw[5]
 repet_des = repet[5]
 elif bt > one_hundred_ten_fsw[5] and bt <= one_hundred_ten_fsw[6]:
 fbt = one_hundred_ten_fsw[6]
 repet_des = repet[6]
 elif bt > one_hundred_ten_fsw[6]:
 fbt = one_hundred_ten_fsw[7]
 repet_des = repet[7]
 ##Calculates T/S if MD is 120 or less.
elif md <= depths[16]:
 fmd = depths[16]
 if bt <= one_hundred_twenty_fsw[0]:
 fbt = one_hundred_twenty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_twenty_fsw[0] and bt <= one_hundred_twenty_fsw[1]:
 fbt = one_hundred_twenty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_twenty_fsw[1] and bt <= one_hundred_twenty_fsw[2]:
 fbt = one_hundred_twenty_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_twenty_fsw[2] and bt <= one_hundred_twenty_fsw[3]:
 fbt = one_hundred_twenty_fsw[3]
 repet_des = repet[3]
 elif bt > one_hundred_twenty_fsw[3] and bt <= one_hundred_twenty_fsw[4]:
 fbt = one_hundred_twenty_fsw[4]
 repet_des = repet[4]
 elif bt > one_hundred_twenty_fsw[4]:
 fbt = one_hundred_twenty_fsw[5]
 repet_des = repet[5]
##Calculates T/S if MD is 130 or less.
elif md <= depths[17]:
 fmd = depths[17]
 if bt <= one_hundred_thirty_fsw[0]:
 fbt = one_hundred_thirty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_thirty_fsw[0] and bt <= one_hundred_thirty_fsw[1]:
 fbt = one_hundred_thirty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_thirty_fsw[1] and bt <= one_hundred_thirty_fsw[2]:
 fbt = one_hundred_thirty_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_thirty_fsw[2] and bt <= one_hundred_thirty_fsw[3]:
 fbt = one_hundred_thirty_fsw[3]
 repet_des = repet[3]
 elif bt > one_hundred_thirty_fsw[3] and bt <= one_hundred_thirty_fsw[4]:
 fbt = one_hundred_thirty_fsw[4]
 repet_des = repet[4]
 elif bt > one_hundred_thirty_fsw[4]:
 fbt = one_hundred_thirty_fsw[5]
 repet_des = repet[5]
##Calculates T/S if MD is 140 or less.
elif md <= depths[18]:
 fmd = depths[18]
 if bt <= one_hundred_fourty_fsw[0]:
 fbt = one_hundred_fourty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_fourty_fsw[0] and bt <= one_hundred_fourty_fsw[1]:
 fbt = one_hundred_fourty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_fourty_fsw[1] and bt <= one_hundred_fourty_fsw[2]:
 fbt = one_hundred_fourty_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_fourty_fsw[2] and bt <= one_hundred_fourty_fsw[3]:
 fbt = one_hundred_fourty_fsw[3]
 repet_des = repet[3]
 elif bt > one_hundred_fourty_fsw[3]:
 fbt = one_hundred_fourty_fsw[4]
 repet_des = repet[4]
##Calculates T/S if MD is 150 or less.
elif md <= depths[19]:
 fmd = depths[19]
 if bt <= one_hundred_fifty_fsw[0]:
 fbt = one_hundred_fifty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_fifty_fsw[0] and bt <= one_hundred_fifty_fsw[1]:
 fbt = one_hundred_fifty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_fifty_fsw[1] and bt <= one_hundred_fifty_fsw[2]:
 fbt = one_hundred_fifty_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_fifty_fsw[2]:
 fbt = one_hundred_fifty_fsw[3]
 repet_des = repet[3]
##Calculates T/S if MD is 160 or less.
elif md <= depths[20]:
 fmd = depths[20]
 if bt <= one_hundred_sixty_fsw[0]:
 fbt = one_hundred_sixty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_sixty_fsw[0] and bt <= one_hundred_sixty_fsw[1]:
 fbt = one_hundred_sixty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_sixty_fsw[1] and bt <= one_hundred_sixty_fsw[2]:
 fbt = one_hundred_sixty_fsw[2]
 repet_des = repet[2]
 elif bt > one_hundred_sixty_fsw[2]:
 fbt = one_hundred_sixty_fsw[3]
 repet_des = repet[3]
##Calculates T/S if MD is 170 or less.
elif md <= depths[21]:
 fmd = depths[21]
 if bt <= one_hundred_seventy_fsw[0]:
 fbt = one_hundred_seventy_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_seventy_fsw[0]:
 fbt = one_hundred_seventy_fsw[1]
 repet_des = repet[1]
##Calculates T/S if MD is 180 or less.
elif md <= depths[22]:
 fmd = depths[22]
 if bt <= one_hundred_eighty_fsw[0]:
 fbt = one_hundred_eighty_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_eighty_fsw[0] and bt <= one_hundred_eighty_fsw[1]:
 fbt = one_hundred_eighty_fsw[1]
 repet_des = repet[1]
 elif bt > one_hundred_eighty_fsw[1]:
 fbt = one_hundred_eighty_fsw[2]
 repet_des = repet[2]
##Calculates T/S if MD is 190 or less.
elif md <= depths[23]:
 fmd = depths[23]
 if bt <= one_hundred_ninety_fsw[0]:
 fbt = one_hundred_ninety_fsw[0]
 repet_des = repet[0]
 elif bt > one_hundred_ninety_fsw[0] and bt <= one_hundred_ninety_fsw[1]:
 fbt = one_hundred_ninety_fsw[1]
 repet_des = repet[1]
print("The table and schedule for the diver is:" + str(fmd) + "/" + str(fbt) + " " + "'" + repet_des + "'")
200_success
146k22 gold badges190 silver badges479 bronze badges
asked Jun 12, 2022 at 23:37
\$\endgroup\$
3
  • \$\begingroup\$ What does fsw stand for? \$\endgroup\$ Commented Jun 13, 2022 at 0:06
  • 1
    \$\begingroup\$ Feet of sea water. I'll edit the post to include the entirety of the program. \$\endgroup\$ Commented Jun 13, 2022 at 0:56
  • \$\begingroup\$ According to your code, 4 minutes at 130 fsw gives you repet designator B, but 4 minutes at 180 fsw gives you repet desginator A. Surely the greater depth should lead to a greater repet designator. What dive table did you use? Is it one of the tables where some of the rows have blanks in column A and the numbers start in a later column? \$\endgroup\$ Commented Jun 24, 2022 at 2:34

2 Answers 2

6
\$\begingroup\$

Pandas was built for this kind of thing, and you can likely get your 700+ line program down to 30 lines of Python and a CSV file. You need to eliminate all of the repetition in your code, pull out the data into a simple database, and use tools that help you.

Note that the last 4 entry in seventy_fsw is almost certainly a transcription error. I have not corrected this.

In the following application of Pandas, searchsorted is an efficient way to locate a row in a sorted series using a binary search.

CSV

depth,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Z
10,57,101,158,245,426,,,,,,,,,,,
15,36,60,88,121,163,271,297,449,,,,,,,,
20,26,43,61,82,106,133,165,205,256,330,416,,,,,
25,20,33,47,62,78,97,117,140,166,198,236,285,354,469,992,1102
30,17,27,38,50,62,76,91,107,125,145,167,193,223,260,307,371
35,14,23,32,42,52,63,74,87,100,115,131,148,168,190,215,232
40,12,20,27,36,44,53,63,73,84,95,108,121,135,151,163,
45,11,17,24,31,39,46,55,63,72,82,92,102,114,125,,
50,9,15,21,28,34,41,48,56,63,71,80,89,92,,,
55,8,14,19,25,31,37,43,50,56,63,71,74,,,,
60,7,12,17,22,28,33,39,45,51,57,63,,,,,
70,6,10,14,19,23,28,32,37,42,47,4,,,,,
80,5,9,12,16,20,24,28,32,36,39,,,,,,
90,4,7,11,14,17,21,24,28,31,33,,,,,,
100,4,6,9,12,15,18,21,2,,,,,,,,
110,3,6,8,11,14,16,19,20,,,,,,,,
120,3,5,7,10,12,15,,,,,,,,,,
130,2,4,6,9,11,12,,,,,,,,,,
140,2,4,6,8,10,,,,,,,,,,,
150,3,5,7,8,,,,,,,,,,,,
160,3,5,6,7,,,,,,,,,,,,
170,4,6,,,,,,,,,,,,,,
180,4,5,6,,,,,,,,,,,,,
190,3,5,,,,,,,,,,,,,,

Python

import pandas as pd
def calculate_dive(max_depth: float, bottom_time: float) -> tuple[
 float, # final max depth
 float, # final feet-of-seawater (fsw)
 str, # final end-of-dive group letter
]:
 """
 This function takes a max_depth and a bottom_time (from the user or
 elsewhere), and produces a tuple of three dive parameters.
 It relies on there being a dive_table.csv with rows per depth and columns per end-of-dive group.
 """
 # Use Pandas to load a comma-separated value file containing the dive table.
 params = pd.read_csv('dive_table.csv', index_col='depth')
 y = params.index.searchsorted(max_depth) # vertical index of max_depth
 depth = params.index[y] # Final depth at that index
 depth_row = params.iloc[y] # Row at that depth
 x = depth_row.searchsorted(bottom_time) # horizontal index of bottom_time
 fsw = depth_row.iloc[x] # feet of sea water at that index
 repet_des = params.columns[x] # group letter at that index
 return depth, fsw, repet_des
def main() -> None:
 print('WARNING! This program will not properly compute decompression or exceptional exposure dives!')
 depth, fsw, repet_des = calculate_dive(
 max_depth=float(input('What is the max depth of the dive in feet? ')),
 bottom_time=float(input('What is the total bottom time of the dive in minutes? ')),
 )
 print(
 f'The table and schedule for the diver is: '
 f"{depth}/{fsw:.0f} '{repet_des}'"
 )
if __name__ == '__main__':
 main()

Output

WARNING! This program will not properly compute decompression or exceptional exposure dives!
What is the max depth of the dive in feet? 22
What is the total bottom time of the dive in minutes? 150
The table and schedule for the diver is: 25/166 'I'
answered Jun 13, 2022 at 0:59
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I don't fully understand what is going on here but it seems like it points me in the right direction, thank you so much! \$\endgroup\$ Commented Jun 13, 2022 at 1:05
1
\$\begingroup\$

Use better program structure

If your code is starting to look repetitious, you can think about subroutines.

In this application, you are interpreting a table according to a set of rules. Since your table seems to be Table 9-7 from the U.S. Navy Diving Manual, here are the steps according to that manual:

  1. Enter the table at the depth equal to or next greater than the maximum depth of the dive.
  2. Follow that row to the right to the bottom time equal to or next greater than the actual bottom time of the dive.
  3. Follow the column up to obtain the repetitive group designator.

Setting aside Step 1 for a moment, once you have identified the row of the table that you have to use, you have a list of numbers, for example the list you called ten_fsw or the list you called one_hundred_fifty_fsw. Step 2 gives you very simple instructions to find the correct position in that list, which will correspond to the correct column of the table (needed for Step 3). This strongly suggests a subroutine. As it happens, if you use pandas as shown in this answer, searchsorted is that subroutine. But if you decided for some reason not to use pandas (or numpy or any other existing code that supplies a suitable subroutine), you could easily write your own subroutine. Even a naïve function that looked at the first element, then the second, and so forth, that stopped when it found a number greater than or equal to the input and returned the index of the number it found, would be sufficient for your application, although searchsorted is faster (especially on long lists).

Just replacing the tedious if-elif statements that search the bottom times with a simple subroutine would greatly shorten your program and make it much easier to understand.

But you might notice that finding the correct entry in depth is the exact same problem as finding the correct column in Step 2: you want the first number that is greater than or equal to your input number. So you can use the same subroutine to find the correct depth as you did to find the correct column at that depth. But this doesn't do you much good if you still need to select one of numerous named lists in based on where you end up in the depth list. To really take advantage of this idea you need to arrange your rows in a single data structure so that you can easily take the result of your subroutine in order to look up the correct row to use. That data structure could be a list of lists, or a dictionary of lists, or the result of pandas.read_csv in this answer. The main thing is you want the lookup of the row to be a built-in language feature (such as subscripting) or a function provided by the other code you use (such as pandas). That way you avoid an if-elif statement for the depth that is still quite long and tedious even with a subroutine for each row.

Use existing tools

This answer shows a way to use pandas in order to write a similar program. The advantage of using an existing tool such as pandas is that it provides a lot of functions that you don't have to write yourself; you just have to know what they are (or look them up). I won't belabor this point since it's pretty well covered already in the other answer.

Check for valid input

If you input a max depth of 90 feet and bottom time of 60 minutes, your program will return repetition designator J. It will also quietly output 33 minutes as the final bottom time. A user who understands the table well might notice the discrepancy and realize the bottom time requires decompression. But it would be better if your program would print an error message rather than returning inconsistent information without explanation.

If you input a max depth greater than 190 feet and any bottom time, your program will return repetition designator A as well as final depth/time 0/0. Again, a clever user might realize this means the output is not to be used, but it would be better if your program would print an error message.

Don't omit important details from your application domain

There are asterisks in the first three rows of the original table. The significance of these is that dives of less than 25 feet max depth can be of unlimited duration without requiring decompression. But if your duration is greater than the last number in the row, you should use the repetition designator in the column that contained the asterisk.

If you enter 10 feet depth and 500 minutes duration into your program, it returns repetition designator E. It should return F.

The last several rows have blanks in the first column or two. If you follow the instructions in Step 2 as written, you will always choose a non-blank entry as your final bottom time. For example, for a max depth of 170 feet and bottom time of 3 minutes the correct repetition designator is C. Your program returns A. There are not even any other clues in the output that this is incorrect, because you return the correct depth/time values 170/4.

Fixing these errors may not be trivial. If you use pandas it is not obvious what data you should put in these entries in the CSV file. You could use negative numbers instead of blank cells at the start of the last several rows, because searchsorted will always find a non-negative value (or go past the end of the list) given a non-negative input.

There are various ways you might deal with the asterisks. The most important thing is not to forget about them.

A concise, well-organized program structure helps by making it easier to spot errors like these.

Other remarks

Sometimes (although not here) it actually makes sense to use if-elif statements. In such cases it is often good to remember that each elif condition implicitly includes the condition "and neither the if condition nor any of the previous elif conditions is true." That implies that the following lines of code,

 if bt <= ten_fsw[0]:
 fbt = ten_fsw[0]
 repet_des = repet[0]
 elif bt > ten_fsw[0] and bt <= ten_fsw[1]:

are exactly equivalent to these lines of code:

 if bt <= ten_fsw[0]:
 fbt = ten_fsw[0]
 repet_des = repet[0]
 elif bt <= ten_fsw[1]:

Similarly for the rest of that if-elif statement in your original program. There may be stylistic reasons in some cases in favor of including conditions such as bt > ten_fsw[0] explicitly, but every bit of code like this that you add to a program is another chance to introduce an error, so I would prefer to avoid it in a case like this.

In particular, if your if-elif statement doesn't end with an "else" clause, check to make sure it is really OK to do nothing in the case where none of the conditions in the if-elif statement occurred.

answered Jul 2, 2022 at 1:17
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.