“akar persamaan kuadratik dalam python” Kode Jawaban

akar persamaan kuadratik dalam python

#how to find roots in quadratic equation
a=int(input('Enter coefficient of x2 :'))
b=int(input('Enter coefficient of x :'))
c=int(input('Enter the constant :'))
if a==0:
  print("a can't be 0")
else:
  D=b**2-4*a*c
  if D>0:
   print('The roots are real and distinct')
   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')
   r=-b/(2*a)
   print('The root is',r)
  else:

   print('The roots are imaginary')
#output:
#real and equal
Enter coefficient of x2 :1
Enter coefficient of x :-4
Enter the constant :4
The roots are real and equal
The root is 2.0
#not real
Enter coefficient of x2 :4
Enter coefficient of x :5
Enter the constant :6
The roots are imaginary
#real and not equal
Enter coefficient of x2 :1
Enter coefficient of x :-5
Enter the constant :6
The roots are real and distinct
The roots are 3.0 and 2.0
Gr@Y_orphan_ViLL@in##

akar persamaan kuadratik dalam python

#root of quadratic equation
a=int(input('Enter coefficient of x2 :'))
b=int(input('Enter coefficient of x :'))
c=int(input('Enter the constant :'))
import math as m
if a==0:
    print(a,'value of a can not be zero')
    print("\n aborting!!!!!!")
else:
    delta=b**2- 4*a*c
    if delta<0:
        root1=((-b + m.sqrt(delta))/(2*a))
        root2=((-b - m.sqrt(delta))/(2*a))
        print('roots are real and distinct')
        print('roots are',root1,'and',root2)
    elif delta==0:
        root=((-b+ m.sqrt(delta))/(2*a))
        print('roots are real and equal')
        print('root is',root,'each')
    else:
        print('roots are imaginary')
Gr@Y_orphan_ViLL@in##

Jawaban yang mirip dengan “akar persamaan kuadratik dalam python”

Pertanyaan yang mirip dengan “akar persamaan kuadratik dalam python”

Lebih banyak jawaban terkait untuk “akar persamaan kuadratik dalam python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya