0% found this document useful (0 votes)
14 views9 pages

Quadratic Equations and Math Programs

The document contains a series of Python programs that solve various mathematical problems, including finding roots of quadratic equations, determining maximum and minimum values, counting vowels in a string, calculating the sum of a series, finding LCM and HCF, identifying prime and perfect numbers, and checking for Armstrong numbers. Each section includes user input prompts and outputs the results of the calculations. The programs demonstrate basic programming concepts and mathematical operations.

Uploaded by

kapilbhaskar1451
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)
14 views9 pages

Quadratic Equations and Math Programs

The document contains a series of Python programs that solve various mathematical problems, including finding roots of quadratic equations, determining maximum and minimum values, counting vowels in a string, calculating the sum of a series, finding LCM and HCF, identifying prime and perfect numbers, and checking for Armstrong numbers. Each section includes user input prompts and outputs the results of the calculations. The programs demonstrate basic programming concepts and mathematical operations.

Uploaded by

kapilbhaskar1451
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

1.

QUADRATIC EQUATION

print("-"*80)
print(" "*30,"[Link] EQUATION")
print("-"*80)
import math
flag= True
while flag:
a=int(input("Enter the coefficient of x^2 : "))
if a==0:
flag=True
else:
flag=False
b=int(input("Enter the coefficient of x : "))
c=int(input("Enter the constant term : "))
d=pow(b,2)-(4*a*c)
if d>0:
print("The roots are real and unequal")
r1=(-b+d**0.5)/(2*a)
r2=(-b-d**0.5)/(2*a)
print("The roots are",r1," and",r2)
elif d==0:
print("The Roots are real and equal")
r1=r2=-b/(2*a)
print("The roots are", r1," and",r2)
else:
print("The roots are imaginary")
d=abs(d)
rp=-b/(2*a)
ip=round(pow(d,0.5)/(2*a),2)
r1=complex(rp,ip)
r2= complex(rp,-ip)
print("The roots are",r1, " and" , r2)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
[Link] EXPRESSION
--------------------------------------------------------------------------------
Enter the coefficient of x^2 : 1
Enter the coefficient of x : 5
Enter the constant term : 6
The roots are real and unequal
The roots are -2.0 and -3.0
END OF PROGRAM
--------------------------------------------------------------------------------
MAXIMUM AND MINIMUM
print("-"*80)
print(" "*30,"[Link] AND MINIMUM")
print("-"*80)
i=1
N=10
while i<=N:
d=int(input("Enter the number : "))
if i==1: Max=Min=d
elif d>Max: Max=d
elif d<Min: Min=d
i+=1
print("The Maximum value is", Max)
print("The Minimum value is", Min)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
[Link] AND MINIMUM
--------------------------------------------------------------------------------
Enter the number : 3
Enter the number : -34
Enter the number : 213
Enter the number : 54
Enter the number : 6
Enter the number : 0
Enter the number : -34
Enter the number : 22
Enter the number : -123
Enter the number : 23
The Maximum value is 213
The Minimum value is -123
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
[Link] COUNT
print("-"*80)
print(" "*30,"[Link] COUNT")
print("-"*80)
na=input("Enter a string : ").upper()

l=len(na)
sa=se=si=so=su=tot=0
i=0
while i <l:
if na[i]=="A": sa+=1
elif na[i]=="E": se+=1
elif na[i]=="I": si+=1
elif na[i]=="O": so+=1
elif na[i]=="U": su+=1
i+=1
tot=sa+se+si+so+su

print("The total number of 'a' in the string is : ",sa)


print("The total number of 'e' in the string is : ",se)
print("The total number of 'i' in the string is : ",si)
print("The total number of 'o' in the string is : ",so)
print("The total number of 'u' in the string is : ",su)
print("The total number of vowels in the string is : ", tot)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
[Link] COUNT
--------------------------------------------------------------------------------
Enter a string : Butterfly is colourful
The total number of 'a' in the string is : 0
The total number of 'e' in the string is : 1
The total number of 'i' in the string is : 1
The total number of 'o' in the string is : 2
The total number of 'u' in the string is : 3
The total number of vowels in the string is : 7
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
[Link] OF THE SERIES

print("-"*80)
print(" "*30,"[Link] OF THE SERIES")
print("-"*80)
x=int(input("Enter the value of x : "))
n=int(input("Enter the limit value : "))
s=1
sg=-1
for i in range(1, n+1):
f=1
for j in range (1, i+1):
f=f*j
s=s+pow(x,i)/f*sg
sg=sg*-1
print("Sum of the series : ", s)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
[Link] OF THE SERIES
--------------------------------------------------------------------------------
Enter the value of x : 2
Enter the limit value : 5
Sum of the series : 0.06666666666666671
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
5. LCM- Euclid's Method

print("-"*80)
print(" "*30,"5. LCM- Euclid's Method")
print("-"*80)
a=int(input("Enter the first number : "))
b=int(input("Enter the second number : "))
t1, t2 = a, b
r=a%b
p=a*b
while r!=0:
a=b
b=r
r=a%b
lcm= p/b
print("The LCM of", t1 ,"and", t2, "is : ", lcm)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
5. LCM- Euclid's Method
--------------------------------------------------------------------------------
Enter the first number : 5
Enter the second number : 25
The LCM of 5 and 25 is : 25.0
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
6. HCF- SUBTRACTION Method

print("-"*80)
print(" "*30,"6. HCF- SUBTRACTION Method")
print("-"*80)
a=int(input("Enter the number 1 : "))
b=int(input("Enter the number 2 : "))
c=int(input("Enter the number 3 : "))
while(a!=b):
if a>b: a=a-b
else: b=b-a
while (a!=c):
if a>c: a=a-c
else: c=c-a
print("The HCF of the numbers is : ", a)
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
6. HCF- SUBTRACTION Method
--------------------------------------------------------------------------------
Enter the number 1 : 2
Enter the number 2 : 18
Enter the number 3 : 24
The HCF of the numbers is : 2
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
7. PRIME NUMBERS

print("-"*80)
print(" "*30,"7. PRIME NUMBERS")
print("-"*80)
lb=int(input("Enter the lower bound : "))
ub=int(input("Enter the upper bound : "))
print("The prime numbers are : ")
while lb<=ub:
c=0
j=2
while j<=lb/2:
if lb%j==0:c=c+1
j=j+1
if c==0: print(lb, end = " " )
lb=lb+1
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)
--------------------------------------------------------------------------------
7. PRIME NUMBERS
--------------------------------------------------------------------------------
Enter the lower bound : 5
Enter the upper bound : 50
The prime numbers are :

5 7 11 13 17 19 23 29 31 37 41 43 47
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
8. PERFECT NUMBERS
print("-"*80)
print(" "*30,"8. PERFECT NUMBERS")
print("-"*80)
u=int(input("Enter the upper bound : "))
n=1
while n<=u:
c=0
j=1
while j<=n:
if(n%j==0):
c=c+j
j=j+1

if c==2*n:print(n," is a perfect number")

n=n+1
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
8. PERFECT NUMBERS
--------------------------------------------------------------------------------
Enter the upper bound : 500
6 is a perfect number
28 is a perfect number
496 is a perfect number
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------
9. ARMSTRONG NUMBERS

print("-"*80)
print(" "*30,"9. ARMSTRONG NUMBERS")
print("-"*80)
n=1
while n<=500:
t=n
nod= 0
while t != 0 :
nod += 1
t = t//10

c=0
t=n
while t!=0:
c=c+pow(t%10,3)
t=t//10
if c==n: print(n," is an Armstrong number")
n=n+1
print("-"*80)
print(" "*35,"END OF PROGRAM")
print("-"*80)

--------------------------------------------------------------------------------
9. ARMSTRONG NUMBERS
--------------------------------------------------------------------------------
1 is an Armstrong number
153 is an Armstrong number
370 is an Armstrong number
371 is an Armstrong number
407 is an Armstrong number
--------------------------------------------------------------------------------
END OF PROGRAM
--------------------------------------------------------------------------------

You might also like