Created
December 11, 2021 00:41
-
-
Save thuwarakeshm/3da1ff0aa87c08b6d804bfffb9cabb4c to your computer and use it in GitHub Desktop.
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 django.urls import path | |
from views import sum_odd_numbers | |
urlpatterns = [ | |
path("sum_odd_numbers/<int:n>", sum_odd_numbers), | |
] |
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 django.http import HttpResponse | |
from django.http.request import HttpRequest | |
def sum_odd_numbers(request: HttpRequest, n: int) -> HttpResponse: | |
"""Sum all the odd numbers less than n""" | |
v = 0 | |
for i in range(n): | |
if i % 2 == 1: | |
v += i | |
return HttpResponse(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment