Created
July 9, 2022 23:25
-
-
Save gmakc-094423/a21f8d2f087939c82fbe7cae68f69907 to your computer and use it in GitHub Desktop.
Решение задач к семинару № 1 (Знакомство с языком Python)
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
""" Напишите программу, которая принимает на вход цифру, обозначающую день недели, и проверяет, является ли этот день выходным. | |
Пример: - 6 -> да - 7 -> да - 1 -> нет """ | |
def InputNumbers(inputText): | |
is_OK = False | |
while not is_OK: | |
try: | |
number = int(input(f"{inputText}")) | |
is_OK = True | |
except ValueError: | |
print("Это не число!") | |
return number | |
def checkNumber(num): | |
if 6 <= num <= 7: | |
print("Yes") | |
elif 0 < num < 6: | |
print("No") | |
else: | |
print("число вне пределов 7 дней") | |
num = InputNumbers("Введите число: ") | |
checkNumber(num) |
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
""" Напишите программу, которая принимает на вход координаты точки (X и Y), | |
причём X ≠ 0 и Y ≠ 0 и выдаёт номер четверти плоскости, в которой находится эта точка (или на какой оси она находится). | |
Пример: - x=34; y=-30 -> 4 - x=2; y=4-> 1 - x=-34; y=-30 -> 3 """ | |
def inputKoord(x): | |
a = [0] * x | |
for i in range(x): | |
is_OK = False | |
while not is_OK: | |
try: | |
number = float(input(f"Введите {i+1} координату: ")) | |
a[i] = number | |
is_OK = True | |
if a[i] == 0: | |
is_OK = False | |
print("Координата не должно быть равна 0 ") | |
except ValueError: | |
print("Ты ошибся. Вводить надо числа!") | |
return a | |
def checkCoordinates(xy): | |
text = 4 | |
if xy[0] > 0 and xy[1] > 0: | |
text = 1 | |
elif xy[0] < 0 and xy[1] > 0: | |
text = 2 | |
elif xy[0] < 0 and xy[1] < 0: | |
text = 3 | |
print(f"Точка находится в {text} четверти плоскости") | |
koordinate = inputKoord(2) | |
checkCoordinates(koordinate) |
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
""" Напишите программу для. проверки истинности утверждения ¬(X ⋁ Y ⋁ Z) = ¬X ⋀ ¬Y ⋀ ¬Z для всех значений предикат. """ | |
def inputNumbers(x): | |
xyz = ["X", "Y", "Z"] | |
a = [] | |
for i in range(x): | |
a.append(input(f"Введите значение {xyz[i]}: ")) | |
return a | |
def checkPredicate(x): | |
left = not (x[0] or x[1] or x[2]) | |
right = not x[0] and not x[1] and not x[2] | |
result = left == right | |
return result | |
statement = inputNumbers(3) | |
if checkPredicate(statement) == True: | |
print(f"Утверждение истинно") | |
else: | |
print(f"Утверждение ложно") |
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
""" Напишите программу, которая принимает на вход координаты двух точек | |
и находит расстояние между ними в 2D пространстве. | |
Пример: - A (3,6); B (2,1) -> 5,09 - A (7,-5); B (1,-1) -> 7,21 """ | |
def inputNumbers(x): | |
xy = ["X", "Y"] | |
a = [] | |
for i in range(x): | |
is_OK = False | |
while not is_OK: | |
try: | |
number = int(input(f"Введите координату по {xy[i]}: ")) | |
a.append(number) | |
is_OK = True | |
except ValueError: | |
print("Ты ошибся. Вводить надо целые числа!") | |
return a | |
def calculateLengthSegment(a, b): | |
lengthSegment = ((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2) ** (0.5) | |
return lengthSegment | |
print("Введите координаты точки А") | |
pointA = inputNumbers(2) | |
print("Введите координаты точки В") | |
pointB = inputNumbers(2) | |
print(f"Длина отрезка: {format(calculateLengthSegment(pointA, pointB), '.2f')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SUPER!