0

How do I replace the last line (12) with unrelated code?

Code 1 https://code.sololearn.com/cgmb7zFslwgT/#py Code 2 https://code.sololearn.com/cENSWI6Pz81P/#py failed code https://code.sololearn.com/cLwNzgf9ZEty/#py The output of the combined codes will pull info from Individual cells of a spreadsheet based on my input. code 2 input: This is a test output: 19, 3 33, 3 34, 3 44, 3 52, 3 34, 4 44, 4 52, 4 26, 5 52, 5 45, 6 30, 6 44, 6 45, 6 code 1 should take one line at a time and look it up: Column 19, Row 3 Column 33, Row 3 Column 34, Row3 etc

2nd Apr 2020, 2:14 AM
Steven
Steven - avatar
13 odpowiedzi
+ 2
Move "y+=1" up above the "row = ..." line. Carefully check indentation. Consistent indentation is a critical part of Python syntax. if s[x]==" ": y+=1 row = ord(s[x])-65-6*s[x].islower()     col = y     print(sheet.cell_value(row, col)) x = x + 1
6th Apr 2020, 11:04 PM
Brian
Brian - avatar
+ 1
Please clarify, "the last line (12)" of what? And what do you mean by "unrelated code"?
6th Apr 2020, 5:01 PM
Brian
Brian - avatar
+ 1
I know it can be frustrating trying to express technical thoughts through this medium. I am happy to help, but less willing if you continue with expressions of negative emotions. Keep it technical and patiently work through the problem. Good solutions start with good problem definitions. So far I understand that you wish to merge functionality of Code 1 and Code 2.  I am unable to test the codes on SoloLearn without xlrd support, but each appears to do what you intended (based on your prior posts). Code 3 looks like a successful merge. Is the next requirement simply to print the contents of the spreadsheet cell? E.g., something Iike this, with coordinates defined by:     row = ord(s[x])-65-6*s[x].islower()     col = y     print(sheet.cell_value(row, col))
6th Apr 2020, 8:03 PM
Brian
Brian - avatar
+ 1
At this time I would expect that Code 3 outputs the same result as Code 2. The print statements are the same. What would you like to change next?
6th Apr 2020, 9:07 PM
Brian
Brian - avatar
+ 1
The requirements are becoming clearer to me. Try inserting the lines that I suggested in my prior post to print the contents of the cell. They would go before line 20.
6th Apr 2020, 9:20 PM
Brian
Brian - avatar
+ 1
The indentation should match the loop indentation. It should be the same as the line that has x = x + 1. (4 spaces)
6th Apr 2020, 10:53 PM
Brian
Brian - avatar
+ 1
It seems that the indentation is still inconsistent. Copy/paste can mess you up that way. If you used tabs in the rest of the code, then you must also use tabs in the new code.
6th Apr 2020, 11:22 PM
Brian
Brian - avatar
0
For crying out loud! i want to take code 1....which (at the moment) outputs cell (0, 0) using line 12 print (sheet.cell_value(0, 0) and replace it with code 2... code 3 is a failed attempt to do that...
6th Apr 2020, 5:08 PM
Steven
Steven - avatar
0
My apologies, in the past, people ask a question (one that is frequently already answered) then disappear and my the site says my post "answered" i receive no more responses. In this case, I feel my original post answered you question. How do I replace the last line (12)[Code 1] with unrelated code? [Code 2]. Unfortunately, code 3 has the same output as code 2(don't ask why, I don't understand either.) Code 1 output Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\steve\Google Drive\All\code\Code> & C:/Users/steve/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/steve/Google Drive/All/code/Code/# Reading an excel file using Python.py" A PS C:\Users\steve\Google Drive\All\code\Code> (Expected) Code 2 output Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\steve\Google Drive\All\code\Code> & C:/Users/steve/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/steve/Google Drive/All/code/Code/imput.py" This is a test 19, 3 33, 3 34, 3 44, 3 52, 3 34, 4 44, 4 52, 4 26, 5 52, 5 45, 6 30, 6 44, 6 45, 6 PS C:\Users\steve\Google Drive\All\code\Code> (Expected) Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\steve\Google Drive\All\code\Code> & C:/Users/steve/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/steve/Google Drive/All/code/Code/import string as st.py" This is a test 19 3 33 3 34 3 44 3 52 3 34 4 44 4 52 4 26 5 52 5 45 6 30 6 44 6 45 6 PS C:\Users\steve\Google Drive\All\code\Code> (Not expected)
6th Apr 2020, 8:38 PM
Steven
Steven - avatar
0
next? I wanted to be able to input word, have them parced out like in code 2 and then each set of numbers be looked up by code 1...am i missing something... or am i explaining it wrong...?
6th Apr 2020, 9:11 PM
Steven
Steven - avatar
0
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\steve\Google Drive\All\code\Code> & C:/Users/steve/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/steve/Google Drive/All/code/Code/import string as st.py" File "c:/Users/steve/Google Drive/All/code/Code/import string as st.py", line 19 row = ord(s[x])-65-6*s[x].islower() ^ IndentationError: unindent does not match any outer indentation level PS C:\Users\steve\Google Drive\All\code\Code>
6th Apr 2020, 10:49 PM
Steven
Steven - avatar
0
# Reading an excel file using Python import xlrd # Give the location of the file loc = (r"C:\Users\steve\Google Drive\All\code\Book2.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # For row 0 and column 0 s = input() #print(len(s)) x=0 y=3 while x<len(s): print(ord(s[x])-65-6*s[x].islower() if s[x].isalpha() else "52",str(y)) if s[x]==" ": row = ord(s[x])-65-6*s[x].islower() col = y print(sheet.cell_value(row, col)) y+=1 x=x+1 #good input=This is a test this is what is looks like to me...
6th Apr 2020, 10:56 PM
Steven
Steven - avatar
0
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\steve\Google Drive\All\code\Code> & C:/Users/steve/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/steve/Google Drive/All/code/Code/import string as st.py" File "c:/Users/steve/Google Drive/All/code/Code/import string as st.py", line 20 row = ord(s[x])-65-6*s[x].islower() ^ IndentationError: unindent does not match any outer indentation level PS C:\Users\steve\Google Drive\All\code\Code>
6th Apr 2020, 11:16 PM
Steven
Steven - avatar