code: def addmags(*mags):
      
      tot = 0
      uncs = []
      for mag in mags:
          try:
              tot += 10**(-0.4*mag)
          except:
              m, dm = mag
              f = 10**(-0.4*m)
              tot += f
              unc = f * (1 - 10**(-0.4*dm))
              uncs.append(unc)
  
      totmag = -2.5*np.log10(tot)
      if len(uncs) > 0:
          f_unc = np.sqrt(np.array([u**2 for u in uncs]).sum())
          return totmag, -2.5*np.log10(1 - f_unc/tot)
      else:
          return totmag
docs: mags is either list of magnitudes or list of (mag, err) pairs