This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz4(maxnum): | |
| fizzbuzz_pairs = ((num, | |
| ("" if num % 3 else "fizz") + ("" if num % 5 else "buzz")) | |
| for num in range(1, maxnum + 1)) | |
| for num, msg in fizzbuzz_pairs: | |
| print("{}: {}".format(num, msg)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz3(maxnum): | |
| fizzbuzz_pairs = [(num, | |
| ("" if num % 3 else "fizz") + ("" if num % 5 else "buzz")) | |
| for num in range(1, maxnum + 1)] | |
| for num, msg in fizzbuzz_pairs: | |
| print("{}: {}".format(num, msg)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz2(max_num): | |
| for num in range(1, max_num+1): | |
| fizz = "fizz" if num % 3 == 0 else "" | |
| buzz = "buzz" if num % 5 == 0 else "" | |
| print("{}: {}".format(num, fizz + buzz)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz1(max_num): | |
| for num in range(1, max_num+1): | |
| msg = "" | |
| if num % 3 == 0: | |
| msg += "fizz" | |
| if num % 5 == 0: | |
| msg += "buzz" | |
| print("{}: {}".format(num, msg)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| def validate_json(*expected_args): | |
| def decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| json_ob = request.get_json() | |
| for expected_arg in expected_args: | |
| if expected_arg not in json_ob or json_ob.get(expected_arg) is None: | |
| abort(400) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| def validate_json(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| json_data = request.get_json() | |
| if "exercise_id" not in json_data or "score" not in json_data: | |
| abort(400) | |
| return func(*args, **kwargs) | |
| return wrapper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @app.route("/addscore", methods=["POST"]) | |
| def add_score(): | |
| json_data = request.get_json() | |
| if "exercise_id" not in json_data or "score" not in json_data: | |
| abort(400) | |
| exercise_id = json_data.get("exercise_id") | |
| score = json_data.get("score") | |
| model.add_attempt(exercise_id, score) | |
| return jsonify(dict(result="success")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @app.route("/addscore", methods=["POST"]) | |
| def add_score(): | |
| json_data = request.get_json() | |
| exercise_id = json_data.get("exercise_id") | |
| score = json_data.get("score") | |
| model.add_attempt(exercise_id, score) | |
| return jsonify(dict(result="success")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def validate_json(*expected_args): | |
| def decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| json_ob = request.get_json() | |
| for expected_arg in expected_args: | |
| if expected_arg not in json_ob or json_ob.get(expected_arg) is None: | |
| abort(400) | |
| return func(*args, **kwargs) | |
| return wrapper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ipython>=2.0 | |
| sqlalchemy>=0.9 | |
| flask>=0.10 | |
| flask-sqlalchemy>=2 | |
| pymysql>=0.6 | |
| nose>=1.3 | |
| requests>=2.5 | |
| beautifulsoup4>=4.0 | |
| uwsgi>=2 |