-
Notifications
You must be signed in to change notification settings - Fork 14
[#H17] Flask_HW #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EvgeniyLyulya
wants to merge
11
commits into
Chudopal:main
Choose a base branch
from
EvgeniyLyulya:HW_Flask
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[#H17] Flask_HW #89
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bbd3056
add shop skeleton
EvgeniyLyulya 5fbac37
added some changes
EvgeniyLyulya 163df60
Merge branch 'Chudopal:main' into main
EvgeniyLyulya 66ba1da
Merge branch 'main' of https://github.com/EvgeniyLyulya/PythonDevelop…
EvgeniyLyulya 613a292
Merge branch 'Chudopal:main' into main
EvgeniyLyulya 7e891c6
Merge branch 'main' of https://github.com/EvgeniyLyulya/PythonDevelop…
EvgeniyLyulya 0d61806
почти готово read fun
EvgeniyLyulya ff4331e
Merge branch 'Chudopal:main' into main
EvgeniyLyulya f29dafe
Merge branch 'Chudopal:main' into main
EvgeniyLyulya baa905d
Merge branch 'Chudopal:main' into main
EvgeniyLyulya a1e2779
[#H15] Flask task_1
EvgeniyLyulya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # """5. Напишите программу магазина. | ||
| # Покупатели могут покупать какие-то продукты в магазине. | ||
|
|
||
| # Возможности покупателя: | ||
| # - посмотреть все товары и цены на них | ||
| # - выбрать товар | ||
| # - посмотреть сумму покупки(сумма цен выбранных товаров) | ||
| # Взаимодействие происходит через консоль. | ||
|
|
||
| # Товары храните просто в какой-нибудь из коллекций. | ||
| # Выбор товара - это ввод пользователем строки названия товара | ||
| # """ | ||
|
|
||
| import json | ||
|
|
||
| products = [ | ||
| ("Rogozhka",100), | ||
| ("Velour",200), | ||
| ("Vicrovelour",300), | ||
| ("Shenil",400), | ||
| ] | ||
|
|
||
| order = [] | ||
|
|
||
| def read_file(filename: str) -> dict: | ||
|
|
||
| with open(filename) as file: | ||
| data = json.load(file) | ||
| return data | ||
|
|
||
|
|
||
| # № function 1 | ||
| def get_all_products() -> list: | ||
| data = read_file('Shops\skin_shop\\app\storage.json') | ||
| id = 0 | ||
| result = '' | ||
| for product in data.get('products'): | ||
| print(product) | ||
| id += 1 | ||
| #result += f'{id}.{product[0]} : {product[1]}$' + "\n" | ||
|
|
||
| return result | ||
|
|
||
| # № function 2 | ||
| def add_product(product_id: int) ->str: | ||
|
|
||
| order.append(products[product_id - 1]) | ||
| result = f'Вы выбрали {products[product_id - 1][0]} стоимость {products[product_id - 1][1]}$' + "\n" | ||
| return result | ||
|
|
||
| # № function 3 | ||
| def get_sum_price() -> str: | ||
| sum = 0 | ||
| for order_item in order: | ||
| sum += order_item[1] | ||
| return sum | ||
|
|
||
|
|
||
| def managment_func(num_func: int): | ||
| result = "" | ||
| if num_func == 1: | ||
| result = get_all_products() | ||
| elif num_func == 2: | ||
| product_id = int(input(get_all_products() + 'Введите номер продукта: ')) | ||
| result = add_product(product_id) | ||
| elif num_func == 3: | ||
| result = f'Сумма покупки {get_sum_price()}$' | ||
| else: | ||
| result = 'Введены неверные значения' | ||
|
|
||
| return result | ||
|
|
||
| def menu(): | ||
| menu = """ | ||
| 0 - Выход | ||
| 1 - Посмотреть товары | ||
| 2 - Добавить в корзину | ||
| 3 - Посмотреть корзину | ||
| """ + "\n" + "Выберите действие: " | ||
| return menu | ||
|
|
||
|
|
||
| def run() -> None: | ||
| choice = "" | ||
| while choice != 'Выход': | ||
| choice = int(input(menu())) | ||
| message = managment_func(choice) | ||
| print(message) | ||
|
|
||
| run() | ||
|
|
||
|
|
||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from flask import Flask | ||
|
|
||
|
|
||
| app = Flask(__name__) | ||
|
|
||
|
|
||
| @app.route("/hello/alex/age/100") | ||
| def index(): | ||
| return "Hello Alex! Your age is 100!" | ||
|
|
||
|
|
||
| @app.route("/hello/bob/age/1") | ||
| def aboud(): | ||
| return "Hello Bob! Your age is 1!" | ||
|
|
||
| app.run(port=4000) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно сделать, чтобы работало динамически, а не только для значения 1