This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from datetime import datetime | |
def todo_manager(): | |
""" | |
Простая программа «Задачник» для управления задачами | |
""" | |
TODO_FILE = 'tasks.txt' | |
def load_tasks(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def save_dict_to_json(): | |
""" | |
Сохраняет словарь Python в файл формата JSON | |
""" | |
print("\n=== СОХРАНЕНИЕ СЛОВАРЯ В JSON ===") | |
# Пример словаря для сохранения | |
data = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_lines_in_file(): | |
""" | |
Подсчитывает количество строк в текстовом файле | |
""" | |
print("=== ПОДСЧЕТ СТРОК В ФАЙЛЕ ===") | |
filename = input("Введите имя файла: ") | |
try: | |
with open(filename, 'r', encoding='utf-8') as file: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shopping_cart(): | |
""" | |
Система учета товаров и корзины покупок | |
""" | |
# Словарь товаров и их цен | |
products = { | |
'хлеб': 50, | |
'молоко': 80, | |
'яйца': 120, | |
'сыр': 300, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_unique_words(): | |
""" | |
Находит все уникальные слова в тексте | |
""" | |
print("=== ПОИСК УНИКАЛЬНЫХ СЛОВ ===") | |
text = input("Введите текст: ").lower() | |
# Удаляем знаки препинания и разбиваем на слова | |
punctuation = '.,!?;:"()[]{}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def students_grades_system(): | |
""" | |
Система учета студентов и их оценок | |
""" | |
students = {} | |
while True: | |
print("\n=== СИСТЕМА УЧЕТА СТУДЕНТОВ ===") | |
print("1. Добавить студента") | |
print("2. Добавить оценку студенту") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def average(numbers): | |
""" | |
Вычисляет среднее значение списка чисел | |
""" | |
if not numbers: # Проверка на пустой список | |
return 0 | |
return sum(numbers) / len(numbers) | |
def average_with_validation(numbers): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacci(n): | |
""" | |
Рекурсивно вычисляет n-ное число Фибоначчи | |
""" | |
if n < 0: | |
raise ValueError("Число должно быть неотрицательным") | |
elif n == 0: | |
return 0 | |
elif n == 1: | |
return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n): | |
""" | |
Вычисляет факториал числа n | |
""" | |
if n < 0: | |
raise ValueError("Факториал определен только для неотрицательных чисел") | |
elif n == 0 or n == 1: | |
return 1 | |
else: | |
result = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_numbers(): | |
print("=== СУММА ЧИСЕЛ ОТ 1 ДО N ===") | |
try: | |
N = int(input("Введите число N: ")) | |
if N <= 0: | |
print("Число должно быть положительным!") | |
return | |
NewerOlder