24 Bai 10773
24 Bai 10773
if choice == '1':
result = num1 + num2
print(f"The result of addition is: {result}")
elif choice == '2':
result = num1 - num2
print(f"The result of subtraction is: {result}")
elif choice == '3':
result = num1 * num2
print(f"The result of multiplication is: {result}")
elif choice == '4':
if num2 != 0:
result = num1 / num2
print(f"The result of division is: {result}")
else:
print("Error! Division by zero.")
else:
print("Invalid input")
print(“24BAI10773”)
calculator()
OUTPUT :-
2 (Rectangle):
o Read length and width
3 (Square):
o Read side length
4 (Circle):
o Read radius
5 (Exit):
o Display exit message
o End
PROGRAM :-
import math
def area_of_square(side):
return side * side
def area_of_circle(radius):
return math.pi * radius * radius
def main():
while True:
print("Select the shape to calculate the area:")
print("1. Triangle")
print("2. Rectangle")
print("3. Square")
print("4. Circle")
print("5. Exit")
if choice == '1':
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
print("The area of the triangle is:",
area_of_triangle(base, height))
elif choice == '2':
length = float(input("Enter the length of the rectangle:
"))
width = float(input("Enter the width of the rectangle: "))
print("The area of the rectangle is:",
area_of_rectangle(length, width))
elif choice == '3':
side = float(input("Enter the side length of the square:
"))
print("The area of the square is:", area_of_square(side))
elif choice == '4':
radius = float(input("Enter the radius of the circle: "))
print("The area of the circle is:", area_of_circle(radius))
elif choice == '5':
print("Exiting the program.")
break
else:
print("Invalid input")
if __name__ == "__main__":
main()
print(“24BAI10773”)
OUTPUT:-
3) QUARDRATIC EQUATION
AIM:-
To solve a quadratic equation of the form ax^2 + bx + c = 0 by
finding its roots.
PROGRAM:-
import math
def solve_quadratic(a, b, c):
discriminant = b**2 - 4*a*c
if discriminant > 0:
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
return f"The roots are: {root1} and {root2}"
elif discriminant == 0:
root = -b / (2*a)
return f"The root is: {root}"
else:
real_part = -b / (2*a)
imaginary_part = math.sqrt(abs(discriminant)) / (2*a)
return f"The roots are: {real_part} + {imaginary_part}i and
{real_part} - {imaginary_part}i"
def main():
print("Solving Quadratic Equation: ax^2 + bx + c = 0")
a = float(input("Enter coe icient a: "))
b = float(input("Enter coe icient b: "))
c = float(input("Enter coe icient c: "))
print(solve_quadratic(a, b, c))
if __name__ == "__main__":
main()
print("24BAI10773")
OUTPUT:-
4) FIND THE GIVEN NUMBER IS ODD OR EVEN :-
AIM:-
To determine whether a given number is odd or even.
ALGORITHM :-
1. Start
2. Read the input number
3. Check if the number is divisible by 2:
o If the remainder is 0, it is an even number
PROGRAM:-
a = int(input("Input the number :"))
if(a%2==0):
print(a,"is even")
else:
print(a,"is odd")
print("24BAI10773")
OUTPUT:-
5) FIND THE GIVEN NUMBER IS POSITIVE AND
NEGATIVE
AIM:-
To determine whether a given number is positive, negative,
or zero.
ALGORITHM:-
-> Start
->Read the input number
->If the number is greater than 0:
Display "Positive"
-> Else if the number is less than 0:
Display "Negative"
-> Else:
Display "Zero"
-> End
PROGRAM:-
a=int(input("input a number"))
if(a>0):
print(a,"is positive")
elif(a<0):
print(a,"is negative")
else:
print(a,"is neither even nor odd")
print("24BAI10773"
OUTPUT:-
6) GIVEN CHARACTER IS VOWEL OR CONSTANT
AIM:- To determine whether a given character is a vowel or
a consonant.
ALGORITHM:-
-> Start
-> Read the input character
->If the character is in 'a', 'e', 'i', 'o', 'u' (both lowercase and
uppercase):
Display "Vowel"
->Else:
Display "Consonant"
-> End
PROGRAM:-
a=input(" input the character:")
if(a=='a'or a=='e'or a=='i'or a=='o'or a=='u'or a=='A'or a=='E'or
a=='I'or a=='O'or a=='U'):
print("it is a vowel")
else:
print("it is a consonant")
print("24BAI10773")
OUTPUT:-
7) SUM OF DIGIT
AIM:- To find the sum of the digits of a given number.
ALGORITHM:-
->Start
-> Read the input number
-> Initialize sum to 0
-> Repeat until the number is greater than 0:
Extract the last digit of the number
Add the digit to sum
Remove the last digit from the number
->Display the sum
->End
PROGRAM:-
a=int(input("input a number :"))
n=a
d=10
sum=0
while(n>0):
c=n%d
sum=sum+c
n=int(n/10)
print("sum of its digits is ",sum)
print("24BAI10773")
OUTPUT:-
8) Find the Given Number is Armstrong or Not. 153
is an Armstrong Number – 13+53+33 = 153
AIM:- To determine whether a given number is an Armstrong
number.
ALGORITHM:-
-> Read the input number.
->Find the number of digits in the input number.
-> Initialize the sum to 0.
-> For each digit in the number, raise it to the
power of the number of digits and add it to the
sum.
->Check if the sum is equal to the original
number.
-> If equal, it is an Armstrong number;
otherwise, it is not.
PROGRAM:-
inp=int(input("input any number"))
dupli=inp
no=0
while(dupli!=0):
no+=(int(dupli%10))**3
dupli=int(dupli/10)
if(no==inp):
print("it is an armstrong number")
else:
print("it is not an armstrong number")
print(“24BAI10773”)
OUTPUT:-
9)
AIM:- the entered number is prime or not
ALGORITHM:-
-> Read the input number.
-> If the number is less than 2, it is not a prime number.
->Iterate from 2 to the square root of the number.
->If the number is divisible by any of these numbers, it is not a
prime number.
->If not divisible by any of these numbers, it is a prime number.
PROGRAM:-
def is_prime(number):
if number <= 1:
return False
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
return False
return True
if is_prime(number):
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")
print("24BAI10773")
OUTPUT:-
def fibonacci_series(n):
a, b = 0, 1
if n <= 0:
print("Invalid input. Please enter a positive number.")
elif n == 1:
print(a)
else:
print(a, b, end=" ")
for i in range(2, n):
c=a+b
print(c, end=" ")
a, b = b, c
fibonacci_series(num_terms)
print("\n24BAI10773")
OUTPUT:-