def mid(strIn,iFrom,iTo):
    # by D@CC
    # created  on 2022EMay30
    # improved on 2024BFeb12
    # Purpose: BASIC-like mid probably for pico
    #  returns  strType, midStr 
    # Comment: similar to Mid(strA,2,3) in BASIC
    #                          col:2,len:3
    # Issue: NOT YET FULLY TESTED
    #        BUT READY FOR TESTING
    # example of use: mid(strA,2,3)
    # mid returns same characters as
    #    the string splice of str(x)[1:4]
    # parmIn 01 strA  str eg "abcdef"
    # parmIn 02 iFrom int eg 2
    # parmIn 03 iTo   int eg 4
    # returns 
    #  parmOut 01 str strType eg "s" or "f" etc
    #  parmOut 02 str strA eg "bcd"
    # accepts types
    #   type     strA      print(Mid(strA,2,3)  BASIC
    #                      print(Mid(strA,a,b)  BASIC
    #                      print(mid(strA,a,b)  Python IX function
    #                      print(str(strA)[a-1:a+b-1] ) equivalent Python
    #   bool     "True"    "rue"
    #   Complex  "(-1+2j)" "-1+"
    #   int      12345     "234"
    #   float    12.34     "2.3"
    #   str      "abcdef"  "bcd"
    #
    # used in article 174
    # called by f3()
    #
    # Functions used:
    # isinstance()  # Issue: maybe "isInstance" instead
    # endswith()
    # float()
    # str()
    # bool()

    x=strIn
    if x == True:
        x="True"
    if x ==False:
        x="False"
    #if end
        
    if isinstance(x,(float,int,str)):
        #print("at 49 x:",x)
        if isinstance(x,str):
            #print("51 checking if complex")
            #print("at 52 x:",x)
            if x.endswith(("j","J")):
                isJend=True
            else:
                isJend=False
            #print("57 isJend:",isJend)
            
            #if(x.endswith("j)") or (x.endswith("J)"):
            #if((x.endswith("j")) or ((x.endswith("J")):
            if isJend:   #if x is probably complex
                print("Issue: Must check syntax of complex")
                print("complex is barely usable on pico")
                #almost complex but without the "(" and ")"
                xReturn="("+x+")"
                xType="sc"
                #print("66 xType:",xType)
                isDone=True
            else:
                #not complex, must be str
                #print("70 not complex, must be str or bool")
                if strIn in [True,False]:
                    print("72 is bool")
                    xType="b"
                    xReturn=x
                else:
                    #print("76 is str")
                    xType="s"
                    xReturn=x
                #if end
                #print("80 xReturn:",xReturn)
                return xType,str(xReturn)[iFrom-1:iFrom+iTo-1]
            #end if
            
            
        # process an integer value
        elif isinstance(x,int):
            print("87 saw int x",x)
            xType="i"
            xReturn=str(x)
            isDone=True
        elif isinstance(x,float):
            print("at 92, float x",x)
            xFloat=x
            xReturn=str(xFloat)
            xType="f"
            isDone=True
            
            
        elif isinstance(x,int):
            print("at 100 after elif x:",x)
            #xInt=int(x)
            xReturn=str(xInt)
            xType="i"
            isDone=True
            
            
            
        # process a float value
        #end if instances of int,float,str,
        
        
        
        
    else:   #presume boolean, not complex
        print("at 115 test Bool")
        if(bool(x)==1):
            xFloat=float(1)
            xReturn=str(xFloat)
            xType="b"
            isDone=True
        #end if
        if(bool(x)==0):
            xFloat=float(0)
            xReturn=str(xFloat)
            xType="b"
            isDone=True
        #end if
        #end of bool processing
    #end if
            
    if isDone:
        if False:
            y="abcdef"
            strY=str(y)[2:3]
            print("at 135 should be returning a value")
            print("136 iFrom:",iFrom)
            print("137 iLen:",iTo)
            print("138 y:",y)
            print("139 str(y)[2:3]:",str(y)[2:3])
        #if end
            
        #print("142 iFrom:",iFrom)
        #print("143 iLen:",iTo)
        #print("144 xType:",xType)
        #print("145 xReturn:",xReturn) 
        return xType,str(xReturn)[iFrom-1:iFrom+iTo-1]
    
    
    else:
        
        print("unknown type, presume s")
    #if end
        
        
    print("155 x:",x)
    xReturn=str(x)[a-1,a+b-1]
    print("157,xReturn:",xReturn)
    xType="s"
    
    
    print("at 161")
    return xType,str(xReturn)[iFrom-1:iFrom+iTo-1]
    #if end
#def end


def go():
    progName="mid_test.py"
    print("progName:",progName)
    print("test mid( ... ,2,3)")
    print("Issues:1")
    while True:
        strA=input("mid string?")
        
        #strA="1+23j"                      #for testing
        
        #print("at 176 strA:",strA)
        strKeep=strA
        #if strA in  :
        
        #if isinstance(strA,("True","False")):
        #print("at 181 strKeep:",strKeep)
        strB,strC = mid(strKeep,2,3)
        #print("at 183")
        print("184 strB,strC:",strB,strC)
    #while end
#def end
go()
#if __name__ == __main__ :
#    go()
#if end
#/mid_pico.py.txt
