Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BMI_Calc_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Выполнил
28 changes: 20 additions & 8 deletions BMI_Calc_1/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
def calculate_bmi(weight, height):
def calculate_bmi(weight, height_cm):
try:
weight = float(weight)
height = float(height)
height = float(height_cm) / 100

if height == 0:
raise ZeroDivisionError

bmi = weight / (height ** 2)
return bmi
except ValueError:
return None
except ZeroDivisionError:
return None


def main():
weight = input("Введите вес (кг): ")
height = input("Введите рост (м): ")
try:
weight = float(input("Введите вес (кг): "))
height_cm = float(input("Введите рост (см): "))

bmi = calculate_bmi(weight, height)
if weight <= 0 or height_cm <= 0:
raise ValueError

if bmi is not None:
print(f"Индекс массы тела (BMI): {bmi:.2f}")
else:
bmi = calculate_bmi(weight, height_cm)

if bmi is not None:
print(f"Индекс массы тела (BMI): {bmi:.2f}")
else:
print("Ошибка: введены некорректные данные!")
except ValueError:
print("Ошибка: введены некорректные данные!")


if __name__ == "__main__":
main()
Empty file.
3 changes: 3 additions & 0 deletions interactive_graphics/graphics/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions interactive_graphics/graphics/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GraphicsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'graphics'
Empty file.
3 changes: 3 additions & 0 deletions interactive_graphics/graphics/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Graph</title>
</head>
<body>
{{ graph_html|safe }}
</body>
</html>
3 changes: 3 additions & 0 deletions interactive_graphics/graphics/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions interactive_graphics/graphics/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# fmt: off

from django.urls import path
from . import views

urlpatterns = [
path('interactive_graph/', views.interactive_graphic, name='interactive_graphic'),
]
15 changes: 15 additions & 0 deletions interactive_graphics/graphics/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

from django.shortcuts import render
import plotly.offline as opy
import plotly.graph_objs as go


def interactive_graphic(request):
x = list(range(-10, 15))
y = [2 * val for val in x]
fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines+markers'))
fig.update_layout(title='Интерактивный график функции y = 2x',
xaxis_title='x', yaxis_title='y')

graph_html = opy.plot(fig, auto_open=False, output_type='div')
return render(request, 'graphics/interactive_graphic.html', {'graph_html': graph_html})
Empty file.
16 changes: 16 additions & 0 deletions interactive_graphics/interactive_graphics/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for interactive_graphics project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings')

application = get_asgi_application()
124 changes: 124 additions & 0 deletions interactive_graphics/interactive_graphics/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
Django settings for interactive_graphics project.

Generated by 'django-admin startproject' using Django 4.2.3.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-3siq-_p%th%ser_w$hduek9ep2h4&o^$@w%9i3#1$*ny-ay%l!'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graphics',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'interactive_graphics.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'interactive_graphics.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
8 changes: 8 additions & 0 deletions interactive_graphics/interactive_graphics/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('graphics/', include('graphics.urls')),
path('graphics/interactive_graph/', include('graphics.urls')),
]
16 changes: 16 additions & 0 deletions interactive_graphics/interactive_graphics/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for interactive_graphics project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings')

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions interactive_graphics/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()