Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie help with input
#9
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?
Reply


Messages In This Thread
Newbie help with input - by LouK - Aug-28-2019, 09:10 PM
RE: Newbie help with input - by jefsummers - Aug-28-2019, 10:16 PM
RE: Newbie help with input - by Yoriz - Aug-28-2019, 10:21 PM
RE: Newbie help with input - by Malt - Aug-29-2019, 05:59 AM
RE: Newbie help with input - by LouK - Aug-29-2019, 02:00 PM
RE: Newbie help with input - by perfringo - Aug-29-2019, 03:34 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 05:38 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 06:50 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 08:41 PM
RE: Newbie help with input - by onlydibs - Dec-22-2019, 04:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Big Grin Newbie to Python - input and branching issue Sherine 3 2,341 Jul-31-2021, 01:09 AM
Last Post: Pedroski55
  Newbie ? Python 3 Input() jlgrunr 1 2,537 Feb-17-2018, 10:26 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020