UnboundLocalError: local variable 'total_seg_cons_loss' referenced before assignment

if args.bv and args.gv:
    total_seg_cons_loss = args.bv_wt * total_seg_cons_loss_1 + args.gv_wt * total_seg_cons_loss_2
elif args.gv:
    total_seg_cons_loss = total_seg_cons_loss_2
elif args.bv:
    total_seg_cons_loss = total_seg_cons_loss_1

#global total_seg_cons_loss
total_cons_loss = total_seg_cons_loss

Based on the error message no condition is met and since no else case is defined total_seg_cons_loss is undefined.
Add an else case and set the value to a default one.