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"])