バルブクリアランスを計算するプログラムを作成しようとしています。これは私がこれまでに作った最初のプログラムなので、私はそれを通して自分の道を混乱させています。さて、これが私がこれまでに得たものです。範囲外のクリアランスを入力すると、本来のように「Right IntakeisOUTOFRANGE」と表示されます。しかし、それが範囲内にある場合、それは私がそれを殺すまで、何度も何度も「右摂取量は範囲内にあります」で私の画面を埋めます。私は何が欠けていますか?
#Clearance calculator
#clearances are in clearances.txt
targets = open("clearances.txt", "r")
lines = targets.readlines() #get target clearances from file
in_min_target = float(lines[2]) #minimum intake clearance
in_max_target = float(lines[4]) #maximum intake clearance
ex_min_target = float(lines[8]) #miminum exhaust clearances
ex_max_target = float(lines[10]) #maximum exhaust clearances
targets.close
target_intake = (in_min_target + in_max_target) / 2 #find the ideal intake
target_exhaust = (ex_min_target + ex_max_target) / 2 #find the ideal exhaust
print "Intake Min: ", in_min_target
print "Intake Max: ", in_max_target
print "Exhaust Min: ", ex_min_target
print "Exhaust Max: ", ex_max_target
print """Target intake: %r
Target Exhaust: %r""" % (target_intake, target_exhaust)
print""
print "Enter current RIGHT side Intake clearance"
cur_r_in = float(raw_input(">"))
print ""
print "Enter current RIGHT side Exhaust clearance"
cur_r_ex = float(raw_input(">"))
print ""
print "Enter current LEFT side Intake clearance"
cur_l_in = float(raw_input(">"))
print ""
print "Enter current LEFT side Exhaust clearance"
cur_l_ex = float(raw_input(">"))
target=5
def in_range(min, max, cur, valve, target):
while min <= cur <= max:
print "%r is in range." % valve
target=1
else:
print "%r is OUT OF RANGE." %valve
target=0
return target
def ex_range(min, max, cur, valve, target):
if min <= cur <= max:
print "%r is in range." % valve
target=1
else:
print "%r is OUT OF RANGE." %valve
target=0
valve = "Right Intake"
print in_range(in_min_target, in_max_target, cur_r_in, valve, target)
print ""
valve = "Right Exhaust"
print ex_range(ex_min_target, ex_max_target, cur_r_ex, valve, target)
print ""
valve = "Left Intake"
print in_range(in_min_target, in_max_target, cur_l_in, valve, target)
print ""
valve = "Left Exhaust"
print ex_range(ex_min_target, ex_max_target, cur_l_ex, valve, target)