Skip to content
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

Ekaterina gurjanova #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
42 changes: 42 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from flask import Flask
app = Flask(__name__)
import datetime
from flask import render_template
import comp
import comp as Comp

collection = []
def init():
comp1 = comp.Comp("Laptop")
collection.append(comp1)
comp2 = comp.Comp("PC")
collection.append(comp2)
comp3 = comp.Comp("Compukter")
collection.append(comp3)

from flask import request

@app.route("/comps/new", methods=["GET", "POST"])
def comps_add():
name = request.form.get("name", default="", type=str)
age = request.form.get("hdd", default="0", type=float)
if name:
comp1 = comp.Comp(name)
comp1.hdd = hdd
collection.append(comp1)
return render_template("new.html")

@app.route('/comps/<name>')
def comp(name):
item = None
for el in collection:
if name == el.name:
item = el
break

return render_template("comp.html", item=item)

@app.route('/comps')
def comps():
return render_template ("comps.html", collection = collection)

47 changes: 47 additions & 0 deletions classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Comp:

def __init__(self, name):
self.name = name
self.__hdd = 0
print("Создание объекта")

@property
def hdd(self):
return self.__hdd

@hdd.setter
def hdd(self, hdd):
if isinstance(hdd,(int, float)) and hdd >= 32 and hdd <= 100:
self.__hdd = hdd
else:
print("Не правильно указан объем жесткого диска")

def increase_hdd(self):
self.hdd = self.hdd + 1

def __str__(self):
return f"name: {self.name}, hdd: {self.hdd}" + """
_______
|.-----.|
||x . x||
||_.-._||
`--)-(--`
__[=== o]___
|:::::::::::|
`-=========-`()
"""
if __name__ == "__main__":
comp1 = Comp("Laptop")
comp1.hdd = 42
comp1.increase_hdd()
print(comp1.name, comp1.hdd)

comp2 = Comp("PC")
comp2.hdd = 99
comp2.increase_hdd()
print(comp2.name, comp2.hdd)

comp2.hdd = 101
comp2.hdd = "Test"

print(comp2)
47 changes: 47 additions & 0 deletions comps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Comp:

def __init__(self, name):
self.name = name
self.__hdd = 0
print("Создание объекта")

@property
def hdd(self):
return self.__hdd

@hdd.setter
def hdd(self, hdd):
if isinstance(hdd,(int, float)) and hdd >= 32 and hdd <= 100:
self.__hdd = hdd
else:
print("Не правильно указан объем жесткого диска")

def increase_hdd(self):
self.hdd = self.hdd + 1

def __str__(self):
return f"name: {self.name}, hdd: {self.hdd}" + """
_______
|.-----.|
||x . x||
||_.-._||
`--)-(--`
__[=== o]___
|:::::::::::|
`-=========-`()
"""
if __name__ == "__main__":
comp1 = Comp("Laptop")
comp1.hdd = 42
comp1.increase_hdd()
print(comp1.name, comp1.hdd)

comp2 = Comp("PC")
comp2.hdd = 99
comp2.increase_hdd()
print(comp2.name, comp2.hdd)

comp2.hdd = 101
comp2.hdd = "Test"

print(comp2)
19 changes: 19 additions & 0 deletions exam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class TemperatureConverter:
def convertTemp(self, temperature, convertTO):
if (convertTO == "F"):
temperature = (temperature - 32) * (5/9)
else:
temperature = temperature * (9/5) + 32

return temperature

if __name__ == "__main__":
con = TemperatureConverter()
res = con.convertTemp(7, 'C')
print (f"7 * C -> {res} * F")
res = con.convertTemp(43, 'C')
print (f"43 * C -> {res} * F")
res = con.convertTemp(64, 'F')
print (res)
res = con.convertTemp(300, 'F')
print (res)
42 changes: 42 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import math

def calc(a, b, x):
y = math.log10(a**2+x)**2/(a+x)**2
return y

def task_a(a,b,xn,xk,dx):
x = xn
res = []
while x <= xk:
y = calc(a, b, x)
res.append((x,y))
x = x + dx
return res

def print_result(result):
for item in result:
x,y = item
print(f"x={x} y={y}")

def task_b(a,b,x_lst):
res = []
for x in x_lst:
y = calc(a, b, x)
res.append((x,y))
return res


if __name__ == "__main__":
a = -2.5
b = 3.4

res = task_a(a,b,3.5,6.5,0.6)
print("-------------Task A -------------")
print_result(res)
print("-------------Лирическое отступление--------------------")
print("Я не знала, куда писать, вапрчто x>5, поэтому просто ввела только значения которые меньше:D")\

x_lst = [5.21, 6.28]
res = task_b(a,b,x_lst)
print("-------------Task B -------------")
print_result(res)
12 changes: 12 additions & 0 deletions templates/comp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>

<head>
<title>Comps</title>
</head>

<body>
<h1>Компьютер</h1>
<p>Имя: {{item.name}} объем жесткого диска {{item.hdd}}</p>
</body>

</html>
17 changes: 17 additions & 0 deletions templates/comps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>

<head>
<title>{{ title }} - Comps</title>
</head>

<body>
<h1>Список компьютеров</h1>
<a href="/comps/new">Добавить</a>
<ul>
{% for item in collection %}
<li><a href="{{ 'comps/%s' % item.name }}"> Имя: {{item.name}} </a></li>
{% endfor %}
</ul>
</body>

</html>
14 changes: 14 additions & 0 deletions templates/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>Comps</title>
</head>
<body>
<h1>Создать компьютер</h1>
<form action="" method="POST">
<p>Имя<input name="name"/></p>
<p>Объем жесткого диска<input type="number" name="hdd" /></p>
<button type="submit">Сохранить</button>
</form>

</body>
</html>