diff --git a/BMI_Calc_1/README.md b/BMI_Calc_1/README.md index e69de29..3f05dd0 100644 --- a/BMI_Calc_1/README.md +++ b/BMI_Calc_1/README.md @@ -0,0 +1 @@ +Выполнил \ No newline at end of file diff --git a/BMI_Calc_1/main.py b/BMI_Calc_1/main.py index ef6e69c..6742436 100644 --- a/BMI_Calc_1/main.py +++ b/BMI_Calc_1/main.py @@ -1,7 +1,11 @@ -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: @@ -9,16 +13,24 @@ def calculate_bmi(weight, height): 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() diff --git a/interactive_graphics/graphics/__init__.py b/interactive_graphics/graphics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/graphics/admin.py b/interactive_graphics/graphics/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/interactive_graphics/graphics/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/interactive_graphics/graphics/apps.py b/interactive_graphics/graphics/apps.py new file mode 100644 index 0000000..20cbe35 --- /dev/null +++ b/interactive_graphics/graphics/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GraphicsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'graphics' diff --git a/interactive_graphics/graphics/migrations/__init__.py b/interactive_graphics/graphics/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/graphics/models.py b/interactive_graphics/graphics/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/interactive_graphics/graphics/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/interactive_graphics/graphics/templates/graphics/interactive_graphic.html b/interactive_graphics/graphics/templates/graphics/interactive_graphic.html new file mode 100644 index 0000000..f65de3f --- /dev/null +++ b/interactive_graphics/graphics/templates/graphics/interactive_graphic.html @@ -0,0 +1,12 @@ + + + + + + + Interactive Graph + + + {{ graph_html|safe }} + + \ No newline at end of file diff --git a/interactive_graphics/graphics/tests.py b/interactive_graphics/graphics/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/interactive_graphics/graphics/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/interactive_graphics/graphics/urls.py b/interactive_graphics/graphics/urls.py new file mode 100644 index 0000000..436c1bc --- /dev/null +++ b/interactive_graphics/graphics/urls.py @@ -0,0 +1,8 @@ +# fmt: off + +from django.urls import path +from . import views + +urlpatterns = [ + path('interactive_graph/', views.interactive_graphic, name='interactive_graphic'), +] \ No newline at end of file diff --git a/interactive_graphics/graphics/views.py b/interactive_graphics/graphics/views.py new file mode 100644 index 0000000..7eb6d48 --- /dev/null +++ b/interactive_graphics/graphics/views.py @@ -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}) diff --git a/interactive_graphics/interactive_graphics/__init__.py b/interactive_graphics/interactive_graphics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/interactive_graphics/asgi.py b/interactive_graphics/interactive_graphics/asgi.py new file mode 100644 index 0000000..e1eb9f8 --- /dev/null +++ b/interactive_graphics/interactive_graphics/asgi.py @@ -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() diff --git a/interactive_graphics/interactive_graphics/settings.py b/interactive_graphics/interactive_graphics/settings.py new file mode 100644 index 0000000..d072a76 --- /dev/null +++ b/interactive_graphics/interactive_graphics/settings.py @@ -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' diff --git a/interactive_graphics/interactive_graphics/urls.py b/interactive_graphics/interactive_graphics/urls.py new file mode 100644 index 0000000..c56b4e0 --- /dev/null +++ b/interactive_graphics/interactive_graphics/urls.py @@ -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')), +] diff --git a/interactive_graphics/interactive_graphics/wsgi.py b/interactive_graphics/interactive_graphics/wsgi.py new file mode 100644 index 0000000..6d8d2ef --- /dev/null +++ b/interactive_graphics/interactive_graphics/wsgi.py @@ -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() diff --git a/interactive_graphics/manage.py b/interactive_graphics/manage.py new file mode 100644 index 0000000..bf31854 --- /dev/null +++ b/interactive_graphics/manage.py @@ -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()