My way of learning is to think of something I need doing, then try a line, step by step, googling each error message and so on. I *don't* look for a complete script, that someone else has already done, to modify. I know it's re-inventing the wheel, but it works for me :)
Anyway, this is my first ever python script. It very simple, but it works. But, I'm just wondering if it is OK as it stands, or could it be a bit more elegant? I mean, would a grizzled old Python hack give a gentle nod of his head and say something like "Not bad, not bad. For a hardware engineer", or would he curl up in the corner, realising 2020 just got worse?...
EDIT: I know it needs things like making sure you can only input numeric values where they're required.
Anyway, this is my first ever python script. It very simple, but it works. But, I'm just wondering if it is OK as it stands, or could it be a bit more elegant? I mean, would a grizzled old Python hack give a gentle nod of his head and say something like "Not bad, not bad. For a hardware engineer", or would he curl up in the corner, realising 2020 just got worse?...
EDIT: I know it needs things like making sure you can only input numeric values where they're required.
# Convert millivolts to engineering units print ("4-20 mA to Engineering units convertor") print ("") def main(): # Set engineering units and range measUnits = input("Enter the units of measurement: ") measMin = input("Enter the minimum measurement value: ") measMin2 = abs(float(measMin)) # removes "minus" bit measMax = input("Enter the maximum measurement value: ") measRange = float(measMin2) + float(measMax) print ("Measurement range is {} {}".format(measRange, measUnits)) # Input measured value rawValue = input("Input mV value: ") # Calculate measured value step1 = float(rawValue) - 400 step2 = step1 / 1600 measValue = (step2 * measRange) - measMin2 output = round(measValue,2) print ("Measured value is {} {}".format(output, measUnits)) main() # Restart? yay or nay? restart = input("Do you want to convert another value? Y/N: ") if restart.lower() == 'y': main() else: print ("Goodbye")