Causes and Treatment of Schizophrenia

Triangle and Even Numbers

Instructions: Triangle and Even Numbers

Write the following two programs using Python Language.

Q1. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.

Q2. Write a program to print the first 10 even numbers starting with 0.

Triangle and Even Numbers

Q1. Solution Triangle and Even Numbers

# Program to check if a triangle is equilateral def is_equilateral(a, b, c): if a == b == c: return True return False def main(): # Accept the lengths of three sides from the user side1 = float(input(“Enter the length of the first side: “)) side2 = float(input(“Enter the length of the second side: “)) side3 = float(input(“Enter the length of the third side: “)) # Check if it’s an equilateral triangle if is_equilateral(side1, side2, side3): print(“The triangle is an equilateral triangle.”) else: print(“The triangle is not an equilateral triangle.”) # Call the main function to run the program main()

Q2. Solution Triangle and Even Numbers

def main(): print(“The first 10 even numbers starting with 0 are:”) for i in range(0, 20, 2): # range starts at 0, goes up to 20, step by 2 print(i) # Call the main function to run the program main()

Explanation:

Q1: Triangle Type Check

    • The user enters the lengths of three sides of a triangle.
    • The program checks if all three sides are equal, indicating an equilateral triangle.
    • If all sides are equal…

 

# Program to check if a triangle is equilateral def is_equilateral(a, b, c): if a == b == c: return True return False def main(): # Accept the lengths of three sides from the user side1 = float(input(“Enter the length of the first side: “)) side2 = float(input(“Enter the length of the second side: “)) side3 = float(input(“Enter the length of the third side: “)) # Check if it’s an equilateral triangle if is_equilateral(side1, side2, side3): print(“The triangle is an equilateral triangle.”) else: print(“The triangle is not an equilateral triangle.”) # Call the main function to run the program main()

Q2. Solution

def main(): print(“The first 10 even numbers starting with 0 are:”) for i in range(0, 20, 2): # range starts at 0, goes up to 20, step by 2 print(i) # Call the main function to run the program main()

Explanation:

  1. Q1: Triangle Type Check
    • The user enters the lengths of three sides of a triangle.
    • The program checks if all three sides are equal, indicating an equilateral triangle.
    • If all sides are equal…

Make Your order Now