I finally got this to run with input() in IDLE as Run Module.
I paste it into Terminal under the Pyton interpreter, the input fails.
If someone could explain this I think it'd help my concept of Python quite a bit.
Thanks!
# CONVERT DECIMAL FEET TO FEET/INCHES
decInput=input("Enter decimal feet: ")
feetDec=float(decInput)
# INTEGERS:
feetInt=int(feetDec)
feetDecFrac= feetDec-feetInt
inchesDec=feetDecFrac*12
inchesInt=int(inchesDec)
feetIntDisp = "%8.0f" % feetInt
inchesIntDisp="%3.0f" % inchesInt
if inchesDec<100:
inchesIntDisp ="%2.0f" % inchesDec
#if inchesDec<10:
# inchesIntDisp ="%1.0f" % inchesDec
# INCH FRACTION:
decA =[0.00000,0.03125,0.06250,0.09375,0.12500,0.15625,0.18750,0.21875,0.25000,0.28125,0.31250,0.34375,0.37500,0.40625,0.43750,0.46875,0.50000,0.53125,0.56250,0.59375,0.62500,0.65625,0.68750,0.71875,0.75000,0.78125,0.81250,0.84375,0.87500,0.90625,0.93750,0.96875,1.00000]
fracA=["0","1/32","1/16","3/32","⅛","5/32","3/16","7/32","¼","9/32","5/16","11/32","⅜","13/32","7/16","15/32","½","17/32","9/16","19/32","⅝","21/32","11/16","23/32","¾","25/32","13/16","27/32","⅞","29/32","15/16","31/32","1"]
k=-1
minDiff=99
inchesDecFrac=inchesDec-inchesInt
while (k<32): # First array position is 0
k=k+1
diff=abs(decA[k]-inchesDecFrac)
if diff<minDiff:
minDiff=diff
closestFrac=fracA[k]
print (feetIntDisp + "' " + inchesIntDisp + "-" + closestFrac + "\"")
My question now is, will it run in Pythonista?
I paste it into Terminal under the Pyton interpreter, the input fails.
If someone could explain this I think it'd help my concept of Python quite a bit.
Thanks!
# CONVERT DECIMAL FEET TO FEET/INCHES
decInput=input("Enter decimal feet: ")
feetDec=float(decInput)
# INTEGERS:
feetInt=int(feetDec)
feetDecFrac= feetDec-feetInt
inchesDec=feetDecFrac*12
inchesInt=int(inchesDec)
feetIntDisp = "%8.0f" % feetInt
inchesIntDisp="%3.0f" % inchesInt
if inchesDec<100:
inchesIntDisp ="%2.0f" % inchesDec
#if inchesDec<10:
# inchesIntDisp ="%1.0f" % inchesDec
# INCH FRACTION:
decA =[0.00000,0.03125,0.06250,0.09375,0.12500,0.15625,0.18750,0.21875,0.25000,0.28125,0.31250,0.34375,0.37500,0.40625,0.43750,0.46875,0.50000,0.53125,0.56250,0.59375,0.62500,0.65625,0.68750,0.71875,0.75000,0.78125,0.81250,0.84375,0.87500,0.90625,0.93750,0.96875,1.00000]
fracA=["0","1/32","1/16","3/32","⅛","5/32","3/16","7/32","¼","9/32","5/16","11/32","⅜","13/32","7/16","15/32","½","17/32","9/16","19/32","⅝","21/32","11/16","23/32","¾","25/32","13/16","27/32","⅞","29/32","15/16","31/32","1"]
k=-1
minDiff=99
inchesDecFrac=inchesDec-inchesInt
while (k<32): # First array position is 0
k=k+1
diff=abs(decA[k]-inchesDecFrac)
if diff<minDiff:
minDiff=diff
closestFrac=fracA[k]
print (feetIntDisp + "' " + inchesIntDisp + "-" + closestFrac + "\"")
My question now is, will it run in Pythonista?