CodeSolved

Solved Programming Questions & Exercises

Identify the type of triangle based on the size of the sides

Practice Easy 1974/ Download 357 Views

Write a program that receives the size of the three sides of the triangle and specifies the type of triangle.

To check if the three sides can form a triangle, you must follow the following conditions:
* The sum of both sides should be greater than the third side. In other words, for sides A, B and C, we must have:
- a + b> c
- a + c> b
- b + c> a

After confirming that the three sides can form a triangle, identify the type of triangle:
* If the three sides are equal, it is an equilateral triangle.
* If the two sides are equal, it is called the equilateral triangle.
* If none of the sides are equal, the triangle will be different.

For example, if your input is as follows:

a = 3
b = 3
c = 3

The expected output should be as follows:

مثلث متساوی‌الساقین

If the input is as follows:

a = 5
b = 5
c = 3

The output should be as follows:

مثلث متساوی‌الساقین

And if the entry is as follows:

a = 4
b = 5
c = 6

The output should be as follows:

مثلث مختلف‌الاضلاع

Please note that your program should first check if the three sides can form a triangle and then specify the type of triangle.

13 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
a = int(input("a: "))
b = int(input("b: "))
c = int(input("c: "))
while((a + b > c) or (a + b > c) or (b + c > a)):
    if a == b == c:        
        print("motasavi Alazla")
    elif (a == b) or (b==c) or (a == c):       
        print("motasavi Alsaghaeen")
    else:        
        print("mokhtalef Alazla")
    break
print("these are'nt a triangle")

while True:
    print("_______________")
    try:
        a = int(input("لطفا مقدار ضلع اول را وارد کنید : "))
        b = int(input("لطفا مقدار ضلع دوم را وارد کنید : "))
        c = int(input("لطفا مقدار ظلع سوم را وارد کنید : "))


        if a + b > c and b + c > a and c + a > b:
            if a == b == c:
                print("مثلث متساوی الضلاع است.")
                break
            elif a == b != c or a == c != b or b == c != a:
                print("مثلث متساوی الثاقین است.")
                break
            else:
                print("مثلث مختلف الضلاع است.")
                break
        else:
            print("مقادیر مربوط به یک مثلث نیست.")
    except ValueError: 
        print("مقادیر وارد شده از نوع عدد نیست.")
from collections import Counter

# gereftan a'dad az karbar
def get():
    while 1:
        try:
            print("----------------------")
            a = abs(float(input("zel' aval mosalas ra vared konid: ")))
            b = abs(float(input("zel' dovom: ")))
            c = abs(float(input("zel' sevom: ")))
            print("----------------------")
            return a, b, c
        except ValueError:
            print("lotfan faghat adad vared konid")
        except:
            print("error!")

# barasi sehat a'dad
def check(a, b, c):
    if a+b > c and a+c > b and b+c > a:
        return 1
    else:
        print("\na'dad vared shode baraye yek mosalas nemibashad\n")
        return 0

# mainloop
def main():
    mosalas = {1:"mokhtalefol azla'", 2:"motasaviol saqein", 3:"motasaviol azla'"}
    while 1:
        nums = get()
        a, b, c = nums
        if check(a, b, c):
            # gereftan bishtarin te'dad tekrar bein a'dad
            nums = Counter(nums)
            maximum = max(nums.values())
                        print("_________________________________________")
            print(f"in mosalas {mosalas[maximum]} ast")
            print("_________________________________________")

            e = input("baraye khoruj az app n ra vared konid: ")
            if e == 'n':
                break
    print("app baste shod...")

main()
Mobboss Download Python
a=int(input('a: '))
b=int(input('b: '))
c=int(input('c: '))
check=(a+b>c or b+c>a or c+a>b)
if(check==True):
    if(a==b==c):
        print("مثلث متساوی الاضلاع")
    elif(a==b or c==a or c==b):
        print("مثلث متساوی الساقین")
    else:
        print("مثلث مختلف الاضلاع")
else:
    print("شکل شما مثلث نیست")

Sadra9292 Download Python
def is_triangle(a:int,b:int,c:int) -> bool:
    """
    This function determine whether is it a triangle or not
    """
    if (a+b>c) and (a+c>b) and (b+c>a):
        return True
    else:
        return False

while True:
    try:
        A=int(input(f"Enter the part a:"))
        B=int(input(f"Enter the part b:"))
        C=int(input(f"Enter the part c:"))
        break
    except ValueError as w:
        print(w)

def type(a:int,b:int,c:int):
    if is_triangle(a,b,c):
        if (a==b==c):
            print(f"The triangle is Motesaviolaslah")
        elif (a==b) or (a==c) or (b==c):
            print(f"The triangle is Motesaviolsaghein")
        else:
            print(f"The triangle is Mokhtalefalaslah")
    else:
        print(f"THis is not a")

type(A,B,C)

while 1:
    try:
        x=int(input("enter the first side>>>"))
        y=int(input("enter the second side>>>"))
        z=int(input("enter the third side>>>"))
        if x<y+z or y<x+z or z<x+y:
            if  x==y==z:
                print("equiletearal triangle")
                break
            elif x==y or y==z or x==z:
                print("isosceles triangle")
            elif x!=y and y!=z and x!=z:
                print("scalene triangle")
    except ValueError:
        print("enter the integer number")
Shina Download Python
a=float(input("Please enter the size of the first side :\n"))
b=float(input("Please enter the size of the second side :\n"))
c=float(input("Please enter the size of the third side :\n"))
if a<b+c and c<a+b and b<a+c:
    print("These three sides form a triangle.")
    if (a==b and a!=c) or (a==c and a!=b) or (b==c and b!=a):
        print("Triangle type: Isosceles triangle")
    elif a==b==c:
        print("Triangle type: Equilateral triangle")
    elif a!=c!=b :
        print("Triangle type: Triangle with different sides")
else:
    print("These three sides do not form a triangle.")
Zaras Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close