18
This question is inspired by the fact that I love seeing questions with equal vote and answer counts...
So here's a simple stack-exchange-api challenge for y'all:
Challenge:
Given a codegolf.stackexchange
question id, output the ratio between the question's votes and number of answers (e.g. votes/answers
).
Specifics:
You may access the internet, but you may only access
stackexchange.com
and its various sub-domains. You may not use URL shorteners.You may take input and give output in any standard format.
You must output the ratio as a decimal number in base 10, with at least 4 {accurate} digits after the decimal (zeros may be truncated).
If the question is unanswered, your program may produce undefined behavior.
You should use the
score
of the question as the vote-count, see here.
This is code-golf, least bytes in each language wins for that language, least bytes overall wins overall.
Here is a sample program in Python 3 + requests
:
import requests
import json
id = input("id> ")
url = "https://api.stackexchange.com/2.2/questions/" + id + "?site=codegolf"
content = requests.get(url).text
question = json.loads(content)["items"][0]
print(float(question["score"]) / question["answer_count"])
Does the ratio need at least 4 decimal digits after the decinal point even if they are zero? E.g. 41/4= 10.25 or 10.2500 – pizzapants184 – 2017-09-18T15:19:13.567
@pizzapants184 10.25 is fine – Socratic Phoenix – 2017-09-18T15:21:40.573
What if the challenge is not answered? Then the ratio would be infinite? – Mr. Xcoder – 2017-09-18T15:37:00.750
Do you mean score or total votes on the question? – AdmBorkBork – 2017-09-18T15:37:33.153
@Mr.Xcoder in that case, undefined behavior is okay – Socratic Phoenix – 2017-09-18T15:37:57.403
@AdmBorkBork technically
score
(which is displayed asvotes
on the main page) – Socratic Phoenix – 2017-09-18T15:38:32.330