- 1
[PYTHON WITH CSV] Can Anyone Sat The Error In This
import csv with open('c:\pyprg\player.csv','w') as f: w = csv.writer(f) n=1 while (n<=10): name = input("Player Name?:" ) score = int(input("Score: ")) w.writerow([name,score]) n+=1 print("Player File created") f.close() searchname=input("Enter the name to be searched ") f=open('c:\\pyprg\\player.csv','r') reader =csv.reader(f) lst=[] for row in reader: lst.append(row) q=0 for row in lst: if searchname in row: print(row) q+=1 if(q==0): print("string not found") f.close()
4 odpowiedzi
+ 3
NITHIVARSHA TP ,
please do not post the code as text here. put the code in playground, save it there and post only a link to the file here.
you should also give a clear description of the error you are encountered, and a description what your code should achieve.
+ 2
NITHIVARSHA TP ,
i have found one `issue`, because the code prints an error message *string not found*, although the string was found in the file.
the reason is an incorrect indentation of this part of the code:
(move the following block to the left, so that `if` is at the very left position)
...
if(q==0):
print("string not found")
>>> i have been running your code on an android device. your code is done for windows. check both path and filename if they are correct, since they
look different in case of the backslash.
+ 1
All looks fine to me.
+ 1
Pls do post each question only once. Multiple posts split the answers and make the discussion messy.
https://www.sololearn.com/discuss/3091907/?ref=app