Chuk norris challenge doubt

why am i getting only 46% accuracy.I replaced all " with " .What might be wrong then?

Hey saurabh,
I don’t think you need to anything apart from just fetching the joke and making a csv.
Would you mind sharing your code on cb.lk/ide so that i can check where you r going wrong

Thanks :slight_smile:

import requests
import json
url=“http://api.icndb.com/jokes/json?"
parameters={
“value”:”"

}
r=requests.get(url,params=parameters)
print(r.url)
p=r.content
print(type§)
pa=json.loads§
print(type(pa))
m=pa[“value”]
print(m) #574 list elements
print(type(m))
print(type(m[0]))
print(m[0])
li=[int(xxx) for xxx in input("enter the id u wanna search- ").split()]
first_line=[“ID,Joke”]
filename=“challengechuknorris.csv”

with open(filename,‘w’,encoding=‘UTF-8’)as f:

HS=','.join(first_line)
HS+='\n'
f.write(HS)\

for i in range(574):
    if(m[i]['id'] in li):
        rs=""
        h=m[i]['id']
        g=m[i]['joke']
        lii=[str(h),g]
        rs=','.join(lii)
        rs+='\n'
        f.write(rs)

Hi,
look the first row of csv file you have generated. It has 3 columns. because the joke had comma in itself, and while converting to csv you have separated the string with , so it becomes a new column.
something like this : 1,Chuck Norris uses ribbed condoms inside out, so he gets the pleasure.

Instead i would recommend you to make a dataframe and use .to_csv() to convert into csv. It is much more cleaner than this way

Thanks :slight_smile:

still cant figure cant.can u please do the required changes in the code above


Code is much cleaner now, If you don’t understand any line of code do let me know.
I hope this will help.
Thanks :slight_smile:

1 Like

what Test/ID.csv is being read?

How would you know which joke to submit out of 574.
So, we consider the x_test file, which is already provided to you. It means you need to get the jokes for only these number of ids that are mentioned in the ID.csv file

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.