Chuck Norris Joke

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)

hey @VinayakSingh11111 ,
you dont need to remove those spaces.

What you need to do is , if there is any space then you need to just write that sentence under quotes in the file.
and it will work fine.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.