0% found this document useful (0 votes)
4 views16 pages

24 Bai 10773

The document outlines various programming tasks including a simple calculator, area calculations for different shapes, solving quadratic equations, and determining properties of numbers (odd/even, positive/negative, prime, Armstrong). Each task includes an aim, algorithm, and a Python program implementation. The document serves as a guide for basic programming exercises in Python.

Uploaded by

raghav122006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

24 Bai 10773

The document outlines various programming tasks including a simple calculator, area calculations for different shapes, solving quadratic equations, and determining properties of numbers (odd/even, positive/negative, prime, Armstrong). Each task includes an aim, algorithm, and a Python program implementation. The document serves as a guide for basic programming exercises in Python.

Uploaded by

raghav122006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1) SIMPLE CALCULATOR

AIM:- Apply the arithmetic operation


ALGORITHM :-
-> Start
-> Display options for the user: Addition, Subtraction,
Multiplication, Division
-> Read the user's choice of operation
-> Ask the user to input two numbers
-> Perform the selected operation based on the user's
choice:
 If Addition, add the two numbers
 If Subtraction, subtract the second number from the first
number
 If Multiplication, multiply the two numbers
 If Division, divide the first number by the second number
(make sure the second number is not zero)
->Display the result
-> End
PROGRAM :-
def calculator():
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

choice = input("Enter choice (1/2/3/4): ")

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))

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) AREA OF TRIANGLE, RECTANGLE, SQUARE AND


CIRCLE
AIM:- To calculate the area of a triangle, rectangle, square,
and circle based on given dimensions.
ALGORITHM :-
-> Start
-> Display options for shapes:
1. Triangle
2. Rectangle
3. Square
4. Circle
5. Exit
-> Read the user's choice of shape
-> If the choice is:
 1 (Triangle):
o Read base and height
o Calculate area using the formula: Area = 0.5 × base ×
height
o Display the area

 2 (Rectangle):
o Read length and width

o Calculate area using the formula: Area = length × width

o Display the area

 3 (Square):
o Read side length

o Calculate area using the formula: Area = side × side

o Display the area

 4 (Circle):
o Read radius

o Calculate area using the formula: Area = π × radius^2

o Display the area

 5 (Exit):
o Display exit message

o End

PROGRAM :-
import math

def area_of_triangle(base, height):


return 0.5 * base * height

def area_of_rectangle(length, width):


return length * width

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")

choice = input("Enter choice (1/2/3/4/5): ")

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

o If the remainder is not 0, it is an odd number

4. Display whether the number is odd or even


5. End

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

number = int(input("Enter a number: "))

if is_prime(number):
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")

print("24BAI10773")

OUTPUT:-

10) FIBBONACI SERIES


AIM:- Fibbonaci Series
ALGORITHM :-
-> Read the input number n (the number of
terms in the Fibonacci series).
-> Initialize the first two terms as 0 and 1.
-> Use a loop to generate the next terms by
adding the last two terms.
-> Continue this until n terms are generated.
PROGRAM:-

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

num_terms = int(input("Enter the number of terms: "))

fibonacci_series(num_terms)
print("\n24BAI10773")
OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy