# f3() formats as f999999.999 where f means float (See endnotes) # MicroPython doesn't process complex numbers import re # to check for regular expressions in a string def f3(x): isDone=False xFloat=3.14159 xType="q" xReturn="" #print("into f3 xReturn:"+xReturn) # process a string #if isinstance(x,(float,int,str,list,dict,tuple)): if isinstance(x,(float,int,str)): if isinstance(x,str): if x.endswith("jJ"): isJend=True else: isJend=False #print("isJend:",isJend) #if(x.endswith("j)") or (x.endswith("J)"): #if((x.endswith("j")) or ((x.endswith("J")): if isJend: #almost complex but without the "(" and ")" xReturn="c" + "("+c+")" xType="c" isDone=True else: #not complex try: xFloat=float(x) xType="f" isDone=True except: xReturn="s"+x isDone=True #end try #end if # process an integer value elif isinstance(x,int): xFloat=float(x) xType="i" isDone=True # process a float value elif isinstance(x,float): xFloat=x xType="f" isDone=True #end if instances of int,float,str, else: #presume boolean if(bool(x)==1): xFloat=float(1) xType="b" isDone=True #end if if(bool(x)==0): xFloat=float(0) xType="b" isDone=True #end if #end of bool processing #end if #process unknown type if isDone==False: #nothing was recognized xReturn="u??????.???" else: if xReturn=="": #create something to return xReturn=xType + str(xFloat) else: #something was created to be returned #doh="doh" pass #end if #end if #print("xReturn:"+xReturn) return xReturn #end def #returns in format f6.3 preceeded by a type character # "b 1.000" # "???????.???" # "s . " # "r 99.00 " # f3(x) # test_f3.py print("progName:test_f3.py") print("Click in run window below, then:") while True: strIn=input("input a number:") print("strIn:",strIn,f3(strIn)) #end while #/f3.py.txt