Practical506 Practical2
Practical506 Practical2
Practical506 Practical2
Practical No: 2
A. Write a function areaTriangle that takes the lengths of three sides of the triangle as
input parameters and returns the area of the triangle as an output. Also, assert that the
sum of the length of any two sides is lesser than the third side. Write a main function
that accepts as command-line arguments and computes the area of a triangle using the
function areaTriangle.
# asserting that the sum of the length of any two sides is lesser than the t
if s1 < maxx:
if s2 < maxx:
if (s1+s2) < s3:
print("Sum of {} & {} is less then {}.".format(s1,s2,s3))
else:
print("Sum of {} & {} is not less then {}.".format(s1,s2,s3))
else:
if (s1+s3) < s2:
print("Sum of {0} & {2} is less then {1}.".format(s1,s2,s3))
else:
print("Sum of {0} & {2} is not less then {1}.".format(s1,s2,s3))
elif s2 < maxx:
if s3 < maxx:
if (s3+s2) < s1:
print("Sum of {2} & {1} is less then {0}.".format(s1,s2,s3))
else:
print("Sum of {2} & {1} is not less then {0}.".format(s1,s2,s3))
else:
if (s1+s2) < s3:
print("Sum of {0} & {1} is less then {2}.".format(s1,s2,s3))
else:
print("Sum of {0} & {1} is not less then {2}.".format(s1,s2,s3))
else:
if (s1+s2) < s3:
print("Sum of {} & {} is less then {}.".format(s1,s2,s3))
else:
print("Sum of {} & {} is not less then {}.".format(s1,s2,s3))
return area
def main():
if(len(sys.argv) > 1):
# storing the input from command line
t1 = sys.argv[1]
localhost:8888/nbconvert/html/final506.ipynb?download=false 1/2
3/1/23, 12:42 AM final506
t2 = sys.argv[2]
t3 = sys.argv[3]
# Calculating the area by calling the areaTriangle function
area = areaTriangle(int(t1),int(t2),int(t3))
print("Area : {:.3f}".format(area))
else:
print("Enter the three sides with the py... statement in cmd itself.")
main()
B. Write a function that takes a string as a parameter and returns a string with every
successive repetitive character replaced with a star(). For Example, ‘balloon’ is returned as
‘balo*n’.
C. Write a function that takes a number as n input parameter and returns the
corresponding text in words; for example, on input 452, the function should return ‘Four
Five Two’. Use a dictionary for mapping to digits to their string representation.
localhost:8888/nbconvert/html/final506.ipynb?download=false 2/2