This commit is contained in:
2025-12-11 18:01:56 +05:00
commit bfa7413f9c
38 changed files with 651 additions and 0 deletions

1
.python-version Normal file
View File

@@ -0,0 +1 @@
3.12

0
README.md Normal file
View File

6
main.py Normal file
View File

@@ -0,0 +1,6 @@
def main():
print("Hello from operators!")
if __name__ == "__main__":
main()

7
pyproject.toml Normal file
View File

@@ -0,0 +1,7 @@
[project]
name = "operators"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

10
task_1.py Normal file
View File

@@ -0,0 +1,10 @@
x = float(input("Введите значение x: "))
if x < -1:
f = x ** 2
elif -1 <= x <= 1:
f = -x
else:
f = x ** 3
print(f"{f:.2f}")

13
task_10.py Normal file
View File

@@ -0,0 +1,13 @@
n = int(input("Введите натуральное число: "))
digit_sum = 0
digit_count = 0
while n > 0:
digit = n % 10
digit_sum += digit
digit_count += 1
n = n // 10
print(f"Сумма цифр: {digit_sum}")
print(f"Количество цифр: {digit_count}")

13
task_11.py Normal file
View File

@@ -0,0 +1,13 @@
k = int(input("Введите цифру k: "))
s = int(input("Введите число s: "))
start = int(input("Введите начало интервала: "))
count = 0
num = start
while count < 10:
if num % 10 == k and num % s == 0:
print(num, end=" ")
count += 1
num += 1
print()

16
task_12.py Normal file
View File

@@ -0,0 +1,16 @@
a = int(input("Введите число a: "))
b = int(input("Введите число b: "))
if a < b:
min_num = a
max_num = b
else:
min_num = b
max_num = a
for num in range(min_num, max_num + 1):
print(num, end=" ")
print()
for num in range(max_num, min_num - 1, -1):
print(num)

29
task_13.py Normal file
View File

@@ -0,0 +1,29 @@
a = int(input("Введите число a: "))
b = int(input("Введите число b: "))
total_sum = 0
for num in range(a, b + 1):
total_sum += num
print(f"Сумма: {total_sum}")
product = 1
for num in range(a, b + 1):
product *= num
print(f"Произведение: {product}")
count = b - a + 1
average = total_sum / count
print(f"Среднее арифметическое: {average:.2f}")
odd_product = 1
odd_count = 0
for num in range(a, b + 1):
if num % 2 != 0:
odd_product *= num
odd_count += 1
if odd_count > 0:
geometric_mean = odd_product ** (1 / odd_count)
print(f"Среднее геометрическое нечетных: {geometric_mean:.2f}")
else:
print("Нечетных чисел нет")

14
task_14.py Normal file
View File

@@ -0,0 +1,14 @@
s = float(input("Введите пробег первого дня (км): "))
p = float(input("Введите процент увеличения: "))
total_distance = s
current_distance = s
print(f"День 1: {current_distance:.1f} км")
for day in range(2, 11):
current_distance = current_distance * (1 + p / 100)
total_distance += current_distance
print(f"День {day}: {current_distance:.1f} км")
print(f"\nСуммарный путь за 10 дней: {total_distance:.1f} км")

13
task_15.py Normal file
View File

@@ -0,0 +1,13 @@
p = float(input("Введите грузоподъемность грузовика (кг): "))
n = int(input("Введите количество предметов: "))
total_weight = 0
for i in range(n):
weight = float(input(f"Введите массу предмета {i + 1} (кг): "))
total_weight += weight
if total_weight <= p:
print("Перевозка возможна")
else:
print("Перевозка невозможна")

11
task_16.py Normal file
View File

@@ -0,0 +1,11 @@
n = int(input("Введите количество районов: "))
total_harvest = 0
for i in range(n):
print(f"\nРайон {i + 1}:")
area = float(input("Введите площадь (га): "))
yield_per_ha = float(input("Введите урожайность (ц/га): "))
total_harvest += area * yield_per_ha
print(f"\nВсего собрано пшеницы: {total_harvest:.1f} ц")

12
task_17.py Normal file
View File

@@ -0,0 +1,12 @@
total_sum = 0
count = 0
while True:
num = int(input("Введите число (0 для завершения): "))
if num == 0:
break
total_sum += num
count += 1
print(f"Сумма: {total_sum}")
print(f"Количество: {count}")

18
task_18.py Normal file
View File

@@ -0,0 +1,18 @@
sentence = input("Введите предложение: ")
vowels = "аеёиоуыэюяАЕЁИОУЫЭЮЯ"
consonants = "бвгджзйклмнпрстфхцчшщБВГДЖЗЙКЛМНПРСТФХЦЧШЩ"
vowel_count = 0
consonant_count = 0
for char in sentence:
if char == ' ':
continue
if char in vowels:
vowel_count += 1
if char in consonants:
consonant_count += 1
print(f"Гласных букв: {vowel_count}")
print(f"Согласных букв: {consonant_count}")

8
task_19.py Normal file
View File

@@ -0,0 +1,8 @@
a = int(input("Введите число a: "))
b = int(input("Введите число b: "))
c = int(input("Введите число c: "))
for num in range(a, b + 1):
if num % c == 0:
print(num, end=" ")
print()

12
task_2.py Normal file
View File

@@ -0,0 +1,12 @@
a = int(input("Введите первое число: "))
b = int(input("Введите второе число: "))
if a > b:
maximum = a
minimum = b
else:
maximum = b
minimum = a
print(f"Максимум: {maximum}")
print(f"Минимум: {minimum}")

11
task_20.py Normal file
View File

@@ -0,0 +1,11 @@
n = int(input("Введите число n: "))
for num in range(100, 1000):
digit1 = num // 100
digit2 = (num // 10) % 10
digit3 = num % 10
if digit1 + digit2 + digit3 == n:
print(num, end=" ")
print()

28
task_21.py Normal file
View File

@@ -0,0 +1,28 @@
n = int(input("Введите количество учеников: "))
boys_total = 0
boys_count = 0
girls_total = 0
girls_count = 0
for i in range(n):
height = int(input(f"Введите рост ученика {i + 1} (для мальчиков - отрицательное): "))
if height < 0:
boys_total += -height
boys_count += 1
else:
girls_total += height
girls_count += 1
if boys_count > 0:
avg_boys = boys_total / boys_count
print(f"Средний рост мальчиков: {avg_boys:.1f} см")
else:
print("Мальчиков нет")
if girls_count > 0:
avg_girls = girls_total / girls_count
print(f"Средний рост девочек: {avg_girls:.1f} см")
else:
print("Девочек нет")

16
task_22.py Normal file
View File

@@ -0,0 +1,16 @@
n = int(input("Введите количество чисел: "))
num = float(input("Введите число 1: "))
maximum = num
minimum = num
for i in range(2, n + 1):
num = float(input(f"Введите число {i}: "))
if num > maximum:
maximum = num
if num < minimum:
minimum = num
print(f"Максимум: {maximum:.2f}")
print(f"Минимум: {minimum:.2f}")

22
task_23.py Normal file
View File

@@ -0,0 +1,22 @@
n = int(input("Введите натуральное число: "))
fib1 = 0
fib2 = 1
if n == 0 or n == 1:
print(f"{n} является членом последовательности Фибоначчи")
else:
is_fibonacci = False
while fib2 < n:
fib_next = fib1 + fib2
fib1 = fib2
fib2 = fib_next
if fib2 == n:
is_fibonacci = True
if is_fibonacci:
print(f"{n} является членом последовательности Фибоначчи")
else:
print(f"{n} не является членом последовательности Фибоначчи")

18
task_24.py Normal file
View File

@@ -0,0 +1,18 @@
n = int(input("Введите количество чисел: "))
prev_num = float(input("Введите число 1: "))
index = 0
for i in range(2, n + 1):
current_num = float(input(f"Введите число {i}: "))
if current_num <= prev_num:
index = i
break
prev_num = current_num
if index == 0:
print("Последовательность упорядочена по возрастанию")
else:
print(f"Последовательность не упорядочена. Нарушение на позиции {index}")

10
task_25.py Normal file
View File

@@ -0,0 +1,10 @@
n = int(input("Введите число n (от 3 до 9): "))
print(f"Таблица умножения на {n}:")
print()
for i in range(1, 11):
for j in range(1, 11):
result = i * j
print(f"{result:4}", end="")
print()

15
task_26.py Normal file
View File

@@ -0,0 +1,15 @@
n = int(input("Введите число n: "))
for num in range(1, n + 1):
divisor_count = 0
for i in range(1, num + 1):
if num % i == 0:
divisor_count += 1
print(f"{num} ", end="")
for i in range(divisor_count):
print("*", end="")
print()

21
task_27.py Normal file
View File

@@ -0,0 +1,21 @@
n = int(input("Введите количество простых чисел: "))
count = 0
num = 2
while count < n:
is_prime = True
for i in range(2, num):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=" ")
count += 1
num += 1
print()

14
task_28.py Normal file
View File

@@ -0,0 +1,14 @@
k = int(input("Введите значение k: "))
k_squared = k * k
found = False
for x in range(1, 31):
for y in range(1, 31):
for z in range(1, 31):
if x * x + y * y + z * z == k_squared:
print(f"x={x}, y={y}, z={z}")
found = True
if not found:
print("Решений не найдено")

28
task_29.py Normal file
View File

@@ -0,0 +1,28 @@
n = int(input("Введите количество чисел: "))
numbers = []
for i in range(n):
num = float(input(f"Введите число {i + 1}: "))
numbers.append(num)
positive = [num for num in numbers if num > 0]
negative = []
for num in numbers:
if num < 0:
negative.append(num)
print(f"\nИсходный список: {numbers}")
print(f"Положительные числа: {positive}")
print(f"Отрицательные числа: {negative}")
if len(positive) > 0:
avg_positive = sum(positive) / len(positive)
print(f"Среднее арифметическое положительных: {avg_positive:.2f}")
if len(negative) > 0:
product = 1
for num in negative:
product *= num
geometric_mean = abs(product) ** (1 / len(negative))
print(f"Среднее геометрическое отрицательных: {geometric_mean:.2f}")

10
task_3.py Normal file
View File

@@ -0,0 +1,10 @@
a = int(input("Введите ширину форточки (см): "))
b = int(input("Введите высоту форточки (см): "))
d = int(input("Введите диаметр головы (см): "))
required_size = d + 2
if a >= required_size and b >= required_size:
print("Вася сможет высунуть голову")
else:
print("Вася не сможет высунуть голову")

48
task_30.py Normal file
View File

@@ -0,0 +1,48 @@
input_str = input("Введите целые числа через пробел: ")
numbers = [int(x) for x in input_str.split()]
print(f"Список: {numbers}")
print()
all_positive_loop = True
for num in numbers:
if num <= 0:
all_positive_loop = False
break
print(f"Все элементы положительные (цикл): {all_positive_loop}")
all_positive_func = all(num > 0 for num in numbers)
print(f"Все элементы положительные (all): {all_positive_func}")
print()
has_zero_loop = False
for num in numbers:
if num == 0:
has_zero_loop = True
break
print(f"Есть нулевой элемент (цикл): {has_zero_loop}")
has_zero_func = any(num == 0 for num in numbers)
print(f"Есть нулевой элемент (any): {has_zero_func}")
print()
all_even_loop = True
for num in numbers:
if num % 2 != 0:
all_even_loop = False
break
print(f"Все элементы четные (цикл): {all_even_loop}")
all_even_func = all(num % 2 == 0 for num in numbers)
print(f"Все элементы четные (all): {all_even_func}")
print()
has_odd_loop = False
for num in numbers:
if num % 2 != 0:
has_odd_loop = True
break
print(f"Есть нечетный элемент (цикл): {has_odd_loop}")
has_odd_func = any(num % 2 != 0 for num in numbers)
print(f"Есть нечетный элемент (any): {has_odd_func}")

13
task_31.py Normal file
View File

@@ -0,0 +1,13 @@
sentence = input("Введите предложение: ")
letter = input("Введите букву для удаления: ")
words = sentence.split()
filtered_words = []
for word in words:
if letter.lower() not in word.lower():
filtered_words.append(word)
result = " ".join(filtered_words)
print(f"Результат: {result}")

36
task_32.py Normal file
View File

@@ -0,0 +1,36 @@
n = int(input("Введите количество рядов: "))
hall = []
for i in range(n):
row_input = input(f"Введите занятость ряда {i + 1} (0 и 1 через пробел): ")
row = [int(x) for x in row_input.split()]
hall.append(row)
free_seats = 0
for row in hall:
for seat in row:
if seat == 0:
free_seats += 1
print(f"\nКоличество свободных мест: {free_seats}")
while True:
response = input("\nХотите проверить конкретное место? (да/нет): ")
if response.lower() != "да":
break
row_num = int(input("Введите номер ряда: "))
seat_num = int(input("Введите номер места: "))
if row_num < 1 or row_num > n:
print("Неверный номер ряда")
continue
if seat_num < 1 or seat_num > len(hall[row_num - 1]):
print("Неверный номер места")
continue
if hall[row_num - 1][seat_num - 1] == 0:
print("Место свободно")
else:
print("Место занято")

47
task_33.py Normal file
View File

@@ -0,0 +1,47 @@
def get_experience(employee):
return employee[4]
n = int(input("Введите количество сотрудников: "))
employees = []
for i in range(n):
data = input(f"Введите данные сотрудника {i + 1} (Фамилия Имя Отчество Пол Стаж): ").split()
employee = [data[0], data[1], data[2], data[3], int(data[4])]
employees.append(employee)
sorted_by_experience = sorted(employees, key=get_experience)
youngest = sorted_by_experience[0]
oldest = sorted_by_experience[-1]
print(f"\nСамый молодой сотрудник (по стажу): {youngest[0]} {youngest[1]} {youngest[2]}, стаж: {youngest[4]} лет")
print(f"Самый старый сотрудник (по стажу): {oldest[0]} {oldest[1]} {oldest[2]}, стаж: {oldest[4]} лет")
men = []
women = []
for employee in employees:
if employee[3] == "М":
men.append(employee)
else:
women.append(employee)
k = input("\nВведите букву для поиска: ")
men_count = 0
for man in men:
if man[1][0].lower() == k.lower():
men_count += 1
women_count = 0
for woman in women:
if woman[1][0].lower() == k.lower():
women_count += 1
print(f"\nМужчин с именем на '{k}': {men_count}")
print(f"Женщин с именем на '{k}': {women_count}")
if men_count > women_count:
print("Больше имен на эту букву у мужчин")
elif women_count > men_count:
print("Больше имен на эту букву у женщин")
else:
print("Одинаковое количество имен на эту букву")

31
task_34.py Normal file
View File

@@ -0,0 +1,31 @@
n = int(input("Введите количество банков: "))
deposits = []
for i in range(n):
data = input(f"Введите данные вклада {i + 1} (Банк Сумма Процент): ").split()
deposit = {
"bank": data[0],
"amount": int(data[1]),
"percent": float(data[2])
}
deposits.append(deposit)
most_affordable = deposits[0]
for deposit in deposits:
if deposit["amount"] < most_affordable["amount"]:
most_affordable = deposit
print(f"\nСамый доступный банк: {most_affordable['bank']}")
print(f"Начальная сумма: {most_affordable['amount']:.2f} руб.")
max_profit_deposit = deposits[0]
max_profit = deposits[0]["amount"] * deposits[0]["percent"] / 100
for deposit in deposits:
profit = deposit["amount"] * deposit["percent"] / 100
if profit > max_profit:
max_profit = profit
max_profit_deposit = deposit
print(f"\nСамый выгодный банк: {max_profit_deposit['bank']}")
print(f"Прибыль за год: {max_profit:.2f} руб.")

39
task_4.py Normal file
View File

@@ -0,0 +1,39 @@
current_day = 11
current_month = 12
current_year = 2025
print("Введите дату рождения первого человека:")
day1 = int(input("День: "))
month1 = int(input("Месяц: "))
year1 = int(input("Год: "))
print("Введите дату рождения второго человека:")
day2 = int(input("День: "))
month2 = int(input("Месяц: "))
year2 = int(input("Год: "))
print("Введите дату рождения третьего человека:")
day3 = int(input("День: "))
month3 = int(input("Месяц: "))
year3 = int(input("Год: "))
age1 = current_year - year1
if (current_month, current_day) < (month1, day1):
age1 -= 1
age2 = current_year - year2
if (current_month, current_day) < (month2, day2):
age2 -= 1
age3 = current_year - year3
if (current_month, current_day) < (month3, day3):
age3 -= 1
print(f"\nПервому человеку {age1} лет")
print(f"Второму человеку {age2} лет")
print(f"Третьему человеку {age3} лет")
dates = [(year1, month1, day1, 1), (year2, month2, day2, 2), (year3, month3, day3, 3)]
oldest = min(dates)[3]
print(f"\nСамый старший - {oldest}-й человек")

15
task_5.py Normal file
View File

@@ -0,0 +1,15 @@
x = int(input("Введите координату x: "))
y = int(input("Введите координату y: "))
if x > 0:
if y > 0:
quarter = 1
else:
quarter = 4
else:
if y > 0:
quarter = 2
else:
quarter = 3
print(f"Точка принадлежит {quarter}-й четверти")

17
task_6.py Normal file
View File

@@ -0,0 +1,17 @@
a = float(input("Введите a: "))
b = float(input("Введите b: "))
c = float(input("Введите c: "))
D = b * b - 4 * a * c
if D < 0:
print("Уравнение не имеет действительных корней")
else:
if D == 0:
x = -b / (2 * a)
print(f"x = {x:.1f}")
else:
x1 = (-b + D ** 0.5) / (2 * a)
x2 = (-b - D ** 0.5) / (2 * a)
print(f"x1 = {x1:.1f}")
print(f"x2 = {x2:.1f}")

12
task_7.py Normal file
View File

@@ -0,0 +1,12 @@
total_sum = 0
count = 0
num = int(input("Введите число (0 для завершения): "))
while num != 0:
total_sum += num
count += 1
num = int(input("Введите число (0 для завершения): "))
print(f"Сумма: {total_sum}")
print(f"Количество: {count}")

7
task_8.py Normal file
View File

@@ -0,0 +1,7 @@
n = int(input("Введите число n: "))
num = 0
while num <= n:
print(num, end=" ")
num += 5
print()

10
task_9.py Normal file
View File

@@ -0,0 +1,10 @@
a = float(input("Введите число a: "))
n = 1
sum_n = 1
while sum_n <= a:
n += 1
sum_n += n
print(f"n = {n}")