Skip to content

Instantly share code, notes, and snippets.

@santiagobasulto
Last active July 7, 2020 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santiagobasulto/9abfd9d6d5da3d010cd116762a6ece1c to your computer and use it in GitHub Desktop.
Save santiagobasulto/9abfd9d6d5da3d010cd116762a6ece1c to your computer and use it in GitHub Desktop.
A simple calculator from file inputs

Example Gist as exercise.

This is the description, and THIS FILE IS MANDATORY.

You can include your markdown description here.

{
"numbers_1.json": "https://gist.githubusercontent.com/santiagobasulto/01ab0d95e6b54328e63d1e31f2c2ef1c/raw/e16bbb932edadb8863763af62deeb3e7eacf01ed/numbers_1.json",
"numbers_2.json": "https://gist.githubusercontent.com/santiagobasulto/01ab0d95e6b54328e63d1e31f2c2ef1c/raw/e16bbb932edadb8863763af62deeb3e7eacf01ed/numbers_2.json"
}
1e864813-b40e-4cb2-a79d-f2370047e4be
import json
def calculate_from_json(file_name):
pass
"""
import json
with open("numbers_1.json") as fp:
print(json.load(fp))
with open("numbers_2.json") as fp:
print(json.load(fp))
"""
print(1 + 1)
import json
def calculate_from_json(file_name):
with open(file_name) as fp:
data = json.load(fp)
a, b = float(data['a']), float(data['b'])
return a + b
def test_file_1():
assert calculate_from_json('numbers_1.json') == 9
def test_file_2():
assert calculate_from_json('numbers_2.json') == 3.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment