Skip to content

Instantly share code, notes, and snippets.

@thuwarakeshm
Created December 11, 2021 00:41
Show Gist options
  • Save thuwarakeshm/3da1ff0aa87c08b6d804bfffb9cabb4c to your computer and use it in GitHub Desktop.
Save thuwarakeshm/3da1ff0aa87c08b6d804bfffb9cabb4c to your computer and use it in GitHub Desktop.
from django.urls import path
from views import sum_odd_numbers
urlpatterns = [
path("sum_odd_numbers/<int:n>", sum_odd_numbers),
]
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