Ok, I'm having trouble with my very first program. If you look down to the two functions, what I want is for if the "cur" value is NOT between the min and max, for it to change the Target variable to "0" so I can use it latter in the program... But it doesn't seem to do it... Am I using "return" wrong? Basically, the functions need to turn target
from 1
to 0
, so that ri_fit
changes to 0, so that my final if
thingys trigger...
Sorry for the terrible code, I've only just begun!
#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 = 1
def in_range(min, max, cur, valve, target): #figures if intake valves are correct
if 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): #figures if exhaust valves are correct
if min <= cur <= max:
print "%r is in range." % valve
target=1
else:
print "%r is OUT OF RANGE." %valve
target=0
return target
ri_fit = 1
re_fit = 1 #Assumes all valves are right, until further notice...
li_fit = 1
le_fit = 1
valve = "Right Intake"
print in_range(in_min_target, in_max_target, cur_r_in, valve, target)
print target
if target == 0:
ri_fit = 0
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)
print ri_fit
if ri_fit==0:
print "Right intake is out of range."
print "Enter current right intake shim size."
ri_cur_shim = int(raw_input(">"))
if re_fit==0:
print "Right exhaust is out of range."
print "Enter current right exhaust shim size."
re_cur_shim = int(raw_input(">"))
if li_fit==0:
print "Right intake is out of range."
print "Enter current right intake shim size."
li_cur_shim = int(raw_input(">"))
if le_fit==0:
print "Right exhaust is out of range."
print "Enter current right exhaust shim size."
le_cur_shim = int(raw_input(">"))