@@ -259,110 +259,8 @@ while True:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'saintpetersburg':
|
||||
shipping_cost = 300.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 12
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'novosibirsk':
|
||||
shipping_cost = 500.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 20
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'ekaterinburg':
|
||||
shipping_cost = 450.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 18
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'kazan':
|
||||
shipping_cost = 380.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 15
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'samara':
|
||||
shipping_cost = 390.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 15
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'sochi':
|
||||
shipping_cost = 400.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 15
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'vladivostok':
|
||||
shipping_cost = 680.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 28
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'krasnodar':
|
||||
shipping_cost = 350.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 12
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'ufa':
|
||||
shipping_cost = 410.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 16
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'perm':
|
||||
shipping_cost = 430.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 16
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'tula':
|
||||
shipping_cost = 300.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 11
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
elif city.lower() == 'kaliningrad':
|
||||
shipping_cost = 480.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 19
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
else:
|
||||
# default calculation for other cities
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 25
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.8
|
||||
if total_price > 12000.0:
|
||||
shipping_cost = 0.0
|
||||
def calculations_price(shipping_cost, total_weight, total_price):
|
||||
|
||||
|
||||
discount = 0.0
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
if city.lower() == 'moscow':
|
||||
shipping_cost = 200.0
|
||||
if total_weight > 5.0:
|
||||
shipping_cost += (total_weight - 5.0) * 10
|
||||
if total_price > 5000.0:
|
||||
shipping_cost = shipping_cost * 0.5
|
||||
if total_price > 10000.0:
|
||||
shipping_cost = 0.0
|
||||
@@ -0,0 +1,58 @@
|
||||
def parse_sensor_data(record):
|
||||
number_data = []
|
||||
plants_data = []
|
||||
for recor in record:
|
||||
if type(recor) is float:
|
||||
number_data.append(recor)
|
||||
if type(recor) is str:
|
||||
plants_data.append(recor)
|
||||
result = (number_data, plants_data)
|
||||
return result
|
||||
|
||||
|
||||
def calculate_statistics(dataset):
|
||||
if not dataset:
|
||||
return []
|
||||
num = 0
|
||||
for data in dataset:
|
||||
num += data
|
||||
mean = num / len(dataset)
|
||||
std = ((sum((data - mean) ** 2)) / len(dataset)) ** 0,5
|
||||
statistic = {"mean": mean,"std": std}
|
||||
return statistic
|
||||
|
||||
|
||||
def normalize_features(features, stats):
|
||||
new_data = []
|
||||
for feat in features:
|
||||
fet = (feat - stats["std"]) / stats["mean"]
|
||||
new_data.append(fet)
|
||||
return new_data
|
||||
|
||||
|
||||
def euclidean_distance(vector_a, vector_b):
|
||||
summ = 0
|
||||
for i in range(len(vector_a)):
|
||||
summ += (vector_a[i] - vector_b[i]) ** 2
|
||||
return summ ** 0,5
|
||||
|
||||
|
||||
def find_k_nearest(train_set, test_point, k):
|
||||
distances = []
|
||||
for train_feater,train_laibel in train_set:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def majority_vote(neighbors):
|
||||
val = {}
|
||||
for lox in neighbors:
|
||||
val[lox] = val.get(lox, 0) +
|
||||
@@ -0,0 +1,44 @@
|
||||
import json
|
||||
|
||||
|
||||
class Config():
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
with open(self.filename, "r", encoding="utf-8") as file:
|
||||
return json.load(file)
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
|
||||
def save(self, data):
|
||||
with open(self.filename, "w", encoding="utf-8") as file:
|
||||
json.dump(data, file,indent=4, ensure_ascii=False)
|
||||
|
||||
def get(self, key, default=None):
|
||||
data = self.load()
|
||||
return data.get(key, default)
|
||||
|
||||
|
||||
def set(self, key, value):
|
||||
data = self.load()
|
||||
data[key]=value
|
||||
self.save(data)
|
||||
|
||||
|
||||
class Application():
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def run(self):
|
||||
username = self.config.get("username","гость")
|
||||
print(f"Hello,{username}")
|
||||
|
||||
def set_username(self, name):
|
||||
self.config.set("username", name)
|
||||
|
||||
config = Config("settings.json")
|
||||
ap = Application(config)
|
||||
ap.set_username("Иван")
|
||||
ap.run()
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
**Тесты:**
|
||||
|
||||
1. Создайте `Config("settings.json")` и `Application(config)`
|
||||
1. Создайте `Config("settings.json")` и ``Application(config)
|
||||
2. Запустите приложение (должно вывести "Гость")
|
||||
3. Установите имя через `set_username("Иван")`
|
||||
4. Запустите снова (должно вывести "Иван")
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"username": "Иван"
|
||||
}
|
||||
Reference in New Issue
Block a user