Compare commits
3 Commits
3290ab91fc
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a401a35b0 | |||
| 8cd4a8b928 | |||
| 2e823d96af |
@@ -0,0 +1,34 @@
|
|||||||
|
def filter_numbers(data):
|
||||||
|
new_data = []
|
||||||
|
for dat in data:
|
||||||
|
if type(dat) is int or float and not bool:
|
||||||
|
new_data.append(float(dat))
|
||||||
|
return new_data
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_average(numbers):
|
||||||
|
result = 0
|
||||||
|
if len(numbers) == 0:
|
||||||
|
result = 0
|
||||||
|
else:
|
||||||
|
for number in numbers:
|
||||||
|
result += float(number)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def find_extremes(numbers):
|
||||||
|
if not numbers:
|
||||||
|
return (None, None)
|
||||||
|
else:
|
||||||
|
return min(numbers), max(numbers)
|
||||||
|
|
||||||
|
|
||||||
|
def analyze_data(data):
|
||||||
|
new_data = filter_numbers(data)
|
||||||
|
print(f"Среднее: {calculate_average(new_data)}")
|
||||||
|
print(f"Минимум: {find_extremes(new_data)[0]}")
|
||||||
|
print(f"Максимум: {find_extremes(new_data)[1]}")
|
||||||
|
|
||||||
|
|
||||||
|
my_list = []
|
||||||
|
analyze_data(my_list)
|
||||||
@@ -259,110 +259,8 @@ while True:
|
|||||||
shipping_cost = shipping_cost * 0.5
|
shipping_cost = shipping_cost * 0.5
|
||||||
if total_price > 10000.0:
|
if total_price > 10000.0:
|
||||||
shipping_cost = 0.0
|
shipping_cost = 0.0
|
||||||
elif city.lower() == 'saintpetersburg':
|
def calculations_price(shipping_cost, total_weight, total_price):
|
||||||
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
|
|
||||||
|
|
||||||
discount = 0.0
|
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,38 @@
|
|||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
|
||||||
|
def validate_length(length):
|
||||||
|
if length < 8:
|
||||||
|
print("Пароль должен быть не менее 8 символов")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def generate_password(length, use_digits, use_special):
|
||||||
|
password_book = string.ascii_letters
|
||||||
|
if use_digits:
|
||||||
|
password_book += string.digits
|
||||||
|
if use_special:
|
||||||
|
password_book += string.punctuation
|
||||||
|
result = "".join(random.choices(password_book, k=length))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def create_passwords(count, length):
|
||||||
|
pasword_list = []
|
||||||
|
i = 0
|
||||||
|
for i in range(count):
|
||||||
|
if validate_length(length):
|
||||||
|
pasword = generate_password(
|
||||||
|
length,
|
||||||
|
use_digits=False,
|
||||||
|
use_special=False
|
||||||
|
)
|
||||||
|
pasword_list.append(pasword)
|
||||||
|
i += 1
|
||||||
|
return pasword_list
|
||||||
|
|
||||||
|
|
||||||
|
print(create_passwords(5, 12))
|
||||||
@@ -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. Запустите приложение (должно вывести "Гость")
|
2. Запустите приложение (должно вывести "Гость")
|
||||||
3. Установите имя через `set_username("Иван")`
|
3. Установите имя через `set_username("Иван")`
|
||||||
4. Запустите снова (должно вывести "Иван")
|
4. Запустите снова (должно вывести "Иван")
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,6 @@ def check_number(item):
|
|||||||
return isinstance(item, (int, float))
|
return isinstance(item, (int, float))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_total_sum(nested_list):
|
def calculate_total_sum(nested_list):
|
||||||
new_summ = 0
|
new_summ = 0
|
||||||
for i in nested_list:
|
for i in nested_list:
|
||||||
@@ -22,4 +21,4 @@ def process_data(data, limit):
|
|||||||
|
|
||||||
|
|
||||||
print(check_number("u"))
|
print(check_number("u"))
|
||||||
print(process_data(data = (3,4,6,6,7,(1000,300)), limit = 100))
|
print(process_data(data=(3, 4, 6, 6, 7, (1000, 300)), limit=100))
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ def count_chars(text):
|
|||||||
def get_top_tuples(my_list):
|
def get_top_tuples(my_list):
|
||||||
return sorted(my_list.items(), key=lambda x: x[1], reverse=True)
|
return sorted(my_list.items(), key=lambda x: x[1], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
print(get_top_tuples(count_chars(safe_input())))
|
print(get_top_tuples(count_chars(safe_input())))
|
||||||
|
|||||||
+1
-4
@@ -5,7 +5,6 @@ class PoemReader():
|
|||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
|
|
||||||
def read_poem(self):
|
def read_poem(self):
|
||||||
with open(self.filename, "r", encoding="utf-8") as file:
|
with open(self.filename, "r", encoding="utf-8") as file:
|
||||||
return json.load(file)["poem_text"]
|
return json.load(file)["poem_text"]
|
||||||
@@ -15,7 +14,6 @@ class Player:
|
|||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
def see_words(self):
|
def see_words(self):
|
||||||
print(f"{self.name} читает наши мысли так, словно это слова на экране.")
|
print(f"{self.name} читает наши мысли так, словно это слова на экране.")
|
||||||
|
|
||||||
@@ -24,7 +22,6 @@ class Universe:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = "Вселенная"
|
self.name = "Вселенная"
|
||||||
|
|
||||||
|
|
||||||
def speak(self):
|
def speak(self):
|
||||||
print("И Вселенная говорит тебе: Я люблю тебя.")
|
print("И Вселенная говорит тебе: Я люблю тебя.")
|
||||||
|
|
||||||
@@ -33,12 +30,12 @@ class EndPoem:
|
|||||||
def __init__(self, reader, player, universe):
|
def __init__(self, reader, player, universe):
|
||||||
self.reader, self.player, self.universe = reader, player, universe
|
self.reader, self.player, self.universe = reader, player, universe
|
||||||
|
|
||||||
|
|
||||||
def play_credits(self):
|
def play_credits(self):
|
||||||
print(self.reader.read_poem())
|
print(self.reader.read_poem())
|
||||||
self.player.see_words()
|
self.player.see_words()
|
||||||
self.universe.speak()
|
self.universe.speak()
|
||||||
|
|
||||||
|
|
||||||
reader = PoemReader(r"data\main.json")
|
reader = PoemReader(r"data\main.json")
|
||||||
player = Player("Дима")
|
player = Player("Дима")
|
||||||
universete = Universe()
|
universete = Universe()
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"username": "Иван"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user