code: def flow_pipe(Diam, HeadLoss, Length, Nu, PipeRough, KMinor):
      
      #Inputs do not need to be checked here because they are checked by
      #functions this function calls.
      if KMinor == 0:
          FlowRate = flow_pipemajor(Diam, HeadLoss, Length, Nu,
                                    PipeRough).magnitude
      else:
          FlowRatePrev = 0
          err = 1.0
          FlowRate = min(flow_pipemajor(Diam, HeadLoss, Length,
                                        Nu, PipeRough).magnitude,
                         flow_pipeminor(Diam, HeadLoss, KMinor).magnitude
                         )
          while err > 0.01:
              FlowRatePrev = FlowRate
              HLFricNew = (HeadLoss * headloss_fric(FlowRate, Diam, Length,
                                                    Nu, PipeRough).magnitude
                           / (headloss_fric(FlowRate, Diam, Length,
                                            Nu, PipeRough).magnitude
                              + headloss_exp(FlowRate, Diam, KMinor).magnitude
                              )
                           )
              FlowRate = flow_pipemajor(Diam, HLFricNew, Length,
                                        Nu, PipeRough).magnitude
              if FlowRate == 0:
                  err = 0.0
              else:
                  err = (abs(FlowRate - FlowRatePrev)
                         / ((FlowRate + FlowRatePrev) / 2)
                         )
      return FlowRate
docs: Return the the flow in a straight pipe.
  
      This function works for both major and minor losses and
      works whether the flow is laminar or turbulent.