Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
80 changes: 80 additions & 0 deletions python/api/fastapi-final/api-project-final/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from fastapi import FastAPI, Header
from fastapi.responses import JSONResponse
from pydantic import BaseModel

app = FastAPI()


@app.get("/sum1n/{n}")
async def read_root(n):
n = int(n)
res = 0
for i in range(n):
res += i
return {"result": res}


@app.get("/fibo")
async def fibnums(n):
n = int(n)
if n <= 0:
return "Please enter the number bigger 0!"
elif n == 1:
return 0
elif n == 2:
return 1
else:
a, b = 0, 1
for _ in range (2, n):
a, b = b, a + b
return JSONResponse(content={"result": b})



@app.post("/reverse")
async def revers_word(string: str = Header(...)):
return {"result": string[::-1]}



element_list = []
# Pydantic model
class ElementItem(BaseModel):
element: str

@app.put("/list/")
async def create_item(item: ElementItem):
element_list.append(item.element)
return {"message": f"Item '{item.element}' updated successfully!"}

@app.get("/list/")
async def get_list():
return {"result": element_list}





class ElementItem(BaseModel):
expr: str

@app.post("/calculator/")
async def calc(item: ElementItem):
operands = item.expr.split(",")
num1 = float(operands[0])
operator = operands[1]
num2 = float(operands[2])

match operator:
case "+":
res = num1 + num2
case "-":
res = num1 - num2
case "/":
if num2 == 0:
return "Division by zero is not allowed."
res = num1 / num2
case "*":
res = num1 * num2

return { "result": res }
Binary file not shown.
39 changes: 39 additions & 0 deletions python/api/fastapi-final/api-project-final/testapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_sum1n():
n = 5
response = client.get(f"/sum1n/{n}")
assert response.status_code == 200
assert response.json() == {"result": 10}

def test_fibo():
n = 5
response = client.get(f"/fibo?n={n}")
assert response.status_code == 200
assert response.json() == {"result": 3}

def test_reverse():
w = "hello"
response = client.post(f"/reverse", headers={"string": w})
assert response.status_code == 200
assert response.json() == {"result": "olleh"}

def test_list_add():
json_data = {"element": "Apple"}
response = client.put(f"/list", json=json_data)
assert response.status_code == 200
assert response.json() == {"message": "Item 'Apple' updated successfully!"}

def test_list_show():
response = client.get(f"/list")
assert response.status_code == 200
assert response.json() == {"result": ["Apple"]}

def test_calculator():
json_data = {"expr": "1,+,1"}
response = client.post(f"/calculator", json=json_data)
assert response.status_code == 200
assert response.json() == {"result": 2.0}
8 changes: 8 additions & 0 deletions python/api/fastapi/api-project/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}
11 changes: 11 additions & 0 deletions python/легкие вопросы/calc_deposit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

def calc_deposit(duration:int, rate:float, sum:int):
res = sum
for i in range(duration):
res += res * rate / 100
print(res)
duration, rate, sum = input("Type number the folowing order duration, rate, sum: ").split()

calc_deposit(int(duration), float(rate), int(sum))

12 changes: 12 additions & 0 deletions python/легкие вопросы/int_cmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

a, b = input("Type two numbers: ").split()
a = int(a)
b = int(b)
if a > b:
print("1")
elif a == b:
print("0")
else:
print("-1")

12 changes: 12 additions & 0 deletions python/легкие вопросы/max_of_three.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

def MaxNum(a):
max_num = a[0]
for i in a:
if i > max_num:
max_num = i
return max_num
a = input("Please enter the 3 numbers: ")
a = list(map(int, a.split()))
print("The largest number is: ", MaxNum(a))

20 changes: 20 additions & 0 deletions python/легкие вопросы/min.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

def min_num(nums):
if 0 <= len(nums) <= 10000:
if not nums:
print("The list is empty!")
return None
res = nums[0]
for i in nums:
if i < res:
res = i
return res
else:
print("The numbers out of range!")

num_input = input("Please enter the numbers, there must be spaces between the numbers.: ")
numbers = list(map(int, num_input.split()))
print("The mininmum number is: ", min_num(numbers))


13 changes: 13 additions & 0 deletions python/легкие вопросы/pow_a_b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

def sum_sqr(n):
num = 0
if int(n) >= 1 and int(n) <= 10860:
for i in range(1, n + 1):
num += i ** 2
print(num)
else:
print("Please provide a positive number and in a range of 1 to 10860!")
num = input("Please enter a number: ")
num = int(num)
sum_sqr(num)
12 changes: 12 additions & 0 deletions python/легкие вопросы/print_even_a_b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

def even_num(a, b):
num = []
for i in range(a, b + 1):
if i % 2 == 0:
num.append(i)
print(num)
a, b = input("Type two numbers: ").split()
a = int(a)
b = int(b)
even_num(a, b)
Loading