This file contains 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 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 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 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 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 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 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 fizzbuzz5(maxnum): | |
fizzbuzz_pairs = ((num, | |
(lambda n: ("" if n % 3 else "fizz") + | |
("" if n % 5 else "buzz") )(num)) | |
for num in range(1, maxnum + 1)) | |
for num, msg in fizzbuzz_pairs: | |
print("{}: {}".format(num, msg)) |
This file contains 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 fizzbuzz6(maxnum): | |
fizzbuzz_pairs = ("{}: {}".format(num, | |
(lambda n: ("" if n % 3 else "fizz") + | |
("" if n % 5 else "buzz") )(num)) | |
for num in range(1, maxnum + 1)) | |
for msg in fizzbuzz_pairs: | |
print(msg) |
This file contains 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 fizzbuzz7(maxnum): | |
fizzbuzz_pairs = "\n".join("{}: {}".format(num, | |
(lambda n: ("" if n % 3 else "fizz") + | |
("" if n % 5 else "buzz") )(num)) | |
for num in range(1, maxnum + 1)) | |
print(fizzbuzz_pairs) |
This file contains 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 fizzbuzz8(maxnum): | |
pairs = (lambda mn: "\n".join("{}: {}".format(num, | |
(lambda n: ("" if n % 3 else "fizz") + | |
("" if n % 5 else "buzz") )(num)) | |
for num in range(1, mn + 1)))(maxnum) | |
print(pairs) |