Добавил:
chrysler_a57_mltbnk
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:семестр 1 / lab8
.py #Type of data check
def typecheck(a,b,c):
check = 0
try:
a = float(a)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is not even a number, so ABC is not a triangle!')
return(check)
try:
b = float(b)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is not even a number, so ABC is not a triangle!')
return(check)
try:
c = float(c)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is not even a number, so ABC is not a triangle!')
return(check)
return(check)
#Side existance
def sidecheck(a, b, c):
check = 0
if a <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
elif b <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
elif c <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
return(check)
#Triangle condition
def sidesumcheck(a,b,c):
check = 0
if c > a + b:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is less then sum of «{a}» and «{b}», so ABC is not a triangle!')
check = 1
return(check)
elif b > a + c:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is less then sum of «{a}» and «{c}», so ABC is not a triangle!')
check = 1
return(check)
elif a > b + c:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is less then sum of «{b}» and «{c}», so ABC is not a triangle!')
check = 1
return(check)
return(check)
#Triangle existance check
def trianglecheck(a, b, c):
check1 = typecheck(a, b, c)
if check1 == 1:
return(0)
a = float(a)
b = float(b)
c = float(c)
check2 = sidecheck(a, b, c)
if check2 == 1:
return(0)
check3 = sidesumcheck(a, b, c)
if check3 == 1:
return(0)
return(a, b, c)
#Triangle type check
def tritypecheck(a, b, c):
if a == b == c:
print(f'ABC is an equal-sided triangle because side «a» is equal to sides «b» and «c»{chr(10)}')
elif a == b:
print(f'ABC is an isosceles triangle because side «a» is equal to side «b»{chr(10)}')
elif a == c:
print(f'ABC is an isosceles triangle because side «a» is equal to side «c»{chr(10)}')
elif b == c:
print(f'ABC is an isosceles triangle because side «b» is equal to side «c»{chr(10)}')
else:
print(f'Triangle ABC is a general triangle{chr(10)}')
return
#Triangle chicking program
print("Input sides of triangle ABC")
a = input("Input side «a»: ")
b = input("Input side «b»: ")
c = input("Input side «c»: " )
n = trianglecheck(a,b,c)
if n != 0:
print(f'{chr(10)}Triangle check successful: ABC is a triangle')
a = n[0]
b = n[1]
c = n[2]
tritypecheck(a, b, c)
else:
print(f'{chr(10)}Triangle check failed: ABC is not a triangle')
def typecheck(a,b,c):
check = 0
try:
a = float(a)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is not even a number, so ABC is not a triangle!')
return(check)
try:
b = float(b)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is not even a number, so ABC is not a triangle!')
return(check)
try:
c = float(c)
except:
check = 1
if check == 1:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is not even a number, so ABC is not a triangle!')
return(check)
return(check)
#Side existance
def sidecheck(a, b, c):
check = 0
if a <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
elif b <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
elif c <= 0:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is not a positive number, so ABC is not a triangle!')
check = 1
return(check)
return(check)
#Triangle condition
def sidesumcheck(a,b,c):
check = 0
if c > a + b:
print(f'{chr(10)}Ha! Wrong input data! «{c}» is less then sum of «{a}» and «{b}», so ABC is not a triangle!')
check = 1
return(check)
elif b > a + c:
print(f'{chr(10)}Ha! Wrong input data! «{b}» is less then sum of «{a}» and «{c}», so ABC is not a triangle!')
check = 1
return(check)
elif a > b + c:
print(f'{chr(10)}Ha! Wrong input data! «{a}» is less then sum of «{b}» and «{c}», so ABC is not a triangle!')
check = 1
return(check)
return(check)
#Triangle existance check
def trianglecheck(a, b, c):
check1 = typecheck(a, b, c)
if check1 == 1:
return(0)
a = float(a)
b = float(b)
c = float(c)
check2 = sidecheck(a, b, c)
if check2 == 1:
return(0)
check3 = sidesumcheck(a, b, c)
if check3 == 1:
return(0)
return(a, b, c)
#Triangle type check
def tritypecheck(a, b, c):
if a == b == c:
print(f'ABC is an equal-sided triangle because side «a» is equal to sides «b» and «c»{chr(10)}')
elif a == b:
print(f'ABC is an isosceles triangle because side «a» is equal to side «b»{chr(10)}')
elif a == c:
print(f'ABC is an isosceles triangle because side «a» is equal to side «c»{chr(10)}')
elif b == c:
print(f'ABC is an isosceles triangle because side «b» is equal to side «c»{chr(10)}')
else:
print(f'Triangle ABC is a general triangle{chr(10)}')
return
#Triangle chicking program
print("Input sides of triangle ABC")
a = input("Input side «a»: ")
b = input("Input side «b»: ")
c = input("Input side «c»: " )
n = trianglecheck(a,b,c)
if n != 0:
print(f'{chr(10)}Triangle check successful: ABC is a triangle')
a = n[0]
b = n[1]
c = n[2]
tritypecheck(a, b, c)
else:
print(f'{chr(10)}Triangle check failed: ABC is not a triangle')
Соседние файлы в папке семестр 1
