промежутое
This commit is contained in:
33
programm1/data_types1.py
Normal file
33
programm1/data_types1.py
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
try:
|
||||
a = int(input("Введите первое целое число: "))
|
||||
b = int(input("Введите второе целое число: "))
|
||||
except ValueError:
|
||||
print("Ошибка: введите целые числа")
|
||||
raise SystemExit(1)
|
||||
|
||||
def fmt(x):
|
||||
return f"{round(x,2):.2f}" if isinstance(x, float) else str(x)
|
||||
|
||||
print(f"a + b = {fmt(a + b)}")
|
||||
print(f"a - b = {fmt(a - b)}")
|
||||
print(f"a * b = {fmt(a * b)}")
|
||||
if b == 0:
|
||||
print("a / b = Ошибка: деление на ноль")
|
||||
print("a // b = Ошибка: деление на ноль")
|
||||
print("a % b = Ошибка: деление на ноль")
|
||||
else:
|
||||
print(f"a / b = {fmt(a / b)}")
|
||||
print(f"a // b = {fmt(a // b)}")
|
||||
print(f"a % b = {fmt(a % b)}")
|
||||
|
||||
print(f"a ** b = {fmt(a ** b)}")
|
||||
|
||||
print(f"a < b -> {a < b}")
|
||||
print(f"a <= b -> {a <= b}")
|
||||
print(f"a > b -> {a > b}")
|
||||
print(f"a >= b -> {a >= b}")
|
||||
print(f"a != b -> {a != b}")
|
||||
print(f"a == b -> {a == b}")
|
||||
|
||||
|
||||
40
programm1/data_types2.py
Normal file
40
programm1/data_types2.py
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
import math
|
||||
|
||||
def cbrt(x):
|
||||
return math.copysign(abs(x) ** (1.0/3.0), x)
|
||||
|
||||
def main():
|
||||
try:
|
||||
x = int(input("Введите x (целое): "))
|
||||
y = int(input("Введите y (целое): "))
|
||||
z = int(input("Введите z (целое): "))
|
||||
except ValueError:
|
||||
print("Ошибка: введите корректные целые числа")
|
||||
return
|
||||
|
||||
inner_den = 6 * y
|
||||
if inner_den == 0:
|
||||
print("Ошибка: деление на ноль (y == 0) во внутренней дроби")
|
||||
return
|
||||
|
||||
inner = (x ** 5 + 7) / inner_den
|
||||
root = cbrt(inner)
|
||||
|
||||
try:
|
||||
mod = z % y
|
||||
except ZeroDivisionError:
|
||||
print("Ошибка: деление на ноль при вычислении z mod y (y == 0)")
|
||||
return
|
||||
|
||||
outer_den = 7 - mod
|
||||
if outer_den == 0:
|
||||
print("Ошибка: внешний знаменатель равен нулю (7 - z mod y == 0)")
|
||||
return
|
||||
|
||||
f = root / outer_den
|
||||
rounded = round(f, 3)
|
||||
|
||||
print(f"Результат (округлён до 3 знаков): {rounded:.3f}")
|
||||
|
||||
main()
|
||||
16
programm1/data_types3.py
Normal file
16
programm1/data_types3.py
Normal file
@@ -0,0 +1,16 @@
|
||||
temp = input().strip()
|
||||
|
||||
def main(score: str):
|
||||
if not score:
|
||||
raise ValueError("Пустой ввод")
|
||||
if not score.isdigit():
|
||||
raise ValueError("Введены не цифры")
|
||||
total: int = 0
|
||||
for x in score:
|
||||
total += int(x)
|
||||
print(f"сумма цифр = {total}")
|
||||
|
||||
try:
|
||||
main(temp)
|
||||
except ValueError as e:
|
||||
print(f"Ошибка: {e}")
|
||||
20
programm1/data_types4.py
Normal file
20
programm1/data_types4.py
Normal file
@@ -0,0 +1,20 @@
|
||||
def solve_from_string(s: str) -> str:
|
||||
s = s.strip()
|
||||
if not s:
|
||||
return "Ошибка: пустой ввод"
|
||||
if not (s.lstrip('-').isdigit()):
|
||||
return "Ошибка: введено не целое число"
|
||||
|
||||
m = int(s)
|
||||
if not (0 < m <= 24 * 60):
|
||||
return "Ошибка: m вне допустимого диапазона"
|
||||
|
||||
hours = m // 60
|
||||
minutes = m % 60
|
||||
return f"{hours} {minutes}"
|
||||
|
||||
try:
|
||||
s = input().strip()
|
||||
except EOFError:
|
||||
s = ''
|
||||
print(solve_from_string(s))
|
||||
15
programm1/data_types5.py
Normal file
15
programm1/data_types5.py
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
try:
|
||||
a, b, m, n = map(float, input().split())
|
||||
except Exception:
|
||||
print("Ошибка: введите 4 числа через пробел")
|
||||
raise SystemExit(1)
|
||||
|
||||
if m > n:
|
||||
m, n = n, m
|
||||
|
||||
if a == 0:
|
||||
print("YES" if b == 0 else "NO")
|
||||
else:
|
||||
x = -b / a
|
||||
print("YES" if m <= x <= n else "NO")
|
||||
21
programm1/data_types6.py
Normal file
21
programm1/data_types6.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
def main():
|
||||
team = input("Введите название команды: ").strip()
|
||||
|
||||
print(f"{team} - чемпион!")
|
||||
|
||||
print('-' * len(team))
|
||||
|
||||
lower = team.lower()
|
||||
print(lower)
|
||||
|
||||
print(len(team))
|
||||
|
||||
print('п' in lower)
|
||||
|
||||
print(lower.count('а'))
|
||||
|
||||
|
||||
|
||||
main()
|
||||
|
||||
5
programm1/data_types7.py
Normal file
5
programm1/data_types7.py
Normal file
@@ -0,0 +1,5 @@
|
||||
def main():
|
||||
state = input("Введите название государства: ").strip()
|
||||
capital = input("Введите название столицы: ").strip()
|
||||
print(f"Государство - {state}, столица - {capital}")
|
||||
main()
|
||||
19
programm1/data_types8.py
Normal file
19
programm1/data_types8.py
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
word = "объектно-ориентированный"
|
||||
|
||||
obj = word[:6]
|
||||
|
||||
orientir = word[9:17]
|
||||
|
||||
tir = word[14:17]
|
||||
|
||||
kot = word[4] + word[7] + word[5]
|
||||
|
||||
renta = word[16] + word[12:15] + word[19]
|
||||
|
||||
print(obj)
|
||||
print(orientir)
|
||||
print(tir)
|
||||
print(kot)
|
||||
print(renta)
|
||||
Reference in New Issue
Block a user