From 24c3366f563e02146fab6f0d2d7c033b44eb9061 Mon Sep 17 00:00:00 2001 From: Stepan Date: Thu, 7 May 2026 00:18:35 +0300 Subject: [PATCH] sort --- c/l1.c | 5 ++++ python/l1.py | 43 ++++++++++++++++++++++++++++++++++ python/l2.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 c/l1.c create mode 100644 python/l1.py create mode 100644 python/l2.py diff --git a/c/l1.c b/c/l1.c new file mode 100644 index 0000000..44f1abc --- /dev/null +++ b/c/l1.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("hello"); + return 0; +} diff --git a/python/l1.py b/python/l1.py new file mode 100644 index 0000000..eb3b324 --- /dev/null +++ b/python/l1.py @@ -0,0 +1,43 @@ +import sys + +pol = input('Начнем(да/нет) ') +sp = [] + +def poll(): + pol1 = float(input('Температура: ')) + pol2 = input('Единица (C/F): ') + if pol2=='C': + x = pol1*1.8+32 + xx = f'{pol1}C = {x}' + sp.append(xx) + print(f'{pol1}C = {x}') + elif pol2=='F': + f = (pol1 - 32)/1.8 + ff = f'{pol1}F = {f}' + sp.append(ff) + print(ff) + else: + print('Введите верную букву') + +def his(): + print(sp) + +def circle(): + while True: + if pol=='да': + poll() + print('1. Продолжить\n2. Закончить\n3. История') + po = input('Число ') + if po=='1': + continue + elif po=='2': + sys.exit(1) + elif po=='3': + his() # Костыль + else: + print('Не то число') + elif pol=='нет': + sys.exit(1) + else: + print('нет') +circle() diff --git a/python/l2.py b/python/l2.py new file mode 100644 index 0000000..5d17d91 --- /dev/null +++ b/python/l2.py @@ -0,0 +1,65 @@ +import sys + +sp = [] # Список для истории + +def add(a, b): + return a + b + +def subtract(a, b): + return a - b + +def multiply(a, b): + return a * b + +def divide(a, b): + if b == 0: + return 'Ошибка: деление на 0' + return a / b +def calculate(n1, op, n2): + if op == '+': + res = add(n1, n2) + elif op == '-': + res = subtract(n1, n2) + elif op == '*': + res = multiply(n1, n2) + elif op == '/': + res = divide(n1, n2) + else: + return 'Неизвестная операция' + return res + +def show_history(): + print('\n--- История ---') + for i, entry in enumerate(sp[-5:], 1): + print(f' {i}. {entry}') + print() + +def calc(): + while True: + try: + n1 = float(input('Первое число: ')) + n2 = float(input('Второе число: ')) + except ValueError: + print('Ошибка: введите число!') + continue + + op = input('Операция (+, -, *, /): ') + + result = calculate(n1, op, n2) + if isinstance(result, str): + print(result) + continue + + entry = f'{n1} {op} {n2} = {result}' + sp.append(entry) + print(entry) + + pol = input('Ещё раз? (да/history/нет): ') + if pol == 'нет': + break + elif pol == 'history': + show_history() + elif pol != 'да': + print('Не тот выбор') + +calc()