def robotize(well): #convert that letter into an integer human_to_robot_row = { "A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7 }; human_to_robot_column = { "1": 0, "2": 8, "3": 16, "4": 24, "5": 32, "6": 40, "7": 48, "8": 56, "9": 64, "10": 72, "11": 80, "12": 88 }; #id human_row by isolating the first character h_row = well[0] print "h_row = "+ h_row #id human_column by isolating 2nd and 3rd character h_column = well[1:3] print "column is " + str(h_column) #convert human well to an integer called robo_well robo_well = human_to_robot_column[h_column] + human_to_robot_row[h_row] print robo_well def humanize(well): print "humanized" #finds the column letter column = int(well)/8 #finds the letter of the row robo_row = well%8 robot_row_to_letter_translation = { 0: "A", 1: "B", 2: "C", 3: "D", 4: "E", 5: "F", 6: "G", 7: "H" } row_letter= robot_row_to_letter_translation[robo_row] print row_letter human_well = row_letter + str(column + 1) print human_well robotize("A1") robotize("H12") #robotize("H13") humanize(2) humanize(18) humanize(91) #TO DO: Clean up unnecessary print statements #Need to find a way to add error messages for invalid human well.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question