Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 16 #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Koval_KM-42.txt
Empty file.
55 changes: 55 additions & 0 deletions lab_16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from math import sqrt

print('\n\tWelcome to lab 16.')
print(' Calculation of the triangle area.')

while True:
try:
a = float(input('Enter the length of side "a"(positive): '))
if a <= 0:
raise ValueError('the value can not be negative!')
break
except ValueError as e:
print(f'The promlem is "{e}", please try again.')

while True:
try:
b = float(input('Enter the length of side "b"(positive): '))
if b <= 0:
raise ValueError('the value can not be negative!')
break
except ValueError as e:
print(f'The promlem is "{e}", please try again.')

while True:
try:
c = float(input('Enter the length of side "c"(positive): '))
if c <= 0:
raise ValueError('the value can not be negative!')
break
except ValueError as e:
print(f'The promlem is "{e}", please try again.')

def check(a,b,c):
if (a+b)>c and (b+c)>a and (a+c)>b:
return True
else:
return False

def triangle_ineq(func):
def inner(a,b,c):
if check(a,b,c)==True:
return func(a,b,c)
else:
return 'You can`t make a triangle from these segments. The sum of two sides should exceed the third.'
return inner

@triangle_ineq
def area_calculation(a, b, c):
p = (a + b + c) / 2
s = p * (p - a) * (p - b) * (p - c)
return f'S = {round(sqrt(s), 3)}'


print(area_calculation(a, b, c))
print('Done!\n')