This is my code for the chuck norris joke problem and I am getting only 52 % accuracy even though I have eliminated all the commas from the joke column
import requests
import json
ids=[]
with open (“ID.csv”,“r”) as file:
idx=1
for id in file.readlines():
if idx!=1:
ids.append(int(id[:-1]))
if idx==474:
ids.append(int(id))
idx+=1
print(ids)
with open(“output.csv”,“w”) as file:
result=""
file.write(“ID,Joke\n”)
for id in ids:
joke_url=f’http://api.icndb.com/jokes/{id}’
response=requests.get(joke_url)
data=json.loads(response.content)
joke=data[‘value’][‘joke’]
# print(joke)
app=""
for word in joke:
word=word.replace(’,’,’’)
app+=word
# print(app)
result+=f’{id},’+app+"\n"
print(result)
file.write(result)