from math import sqrt a=float(input("Please enter first number: ")) b=float(input("Please enter second number: ")) c=float(input("Please enter third number: ")) d=b*b-4*a*c; # finding determinant if(d==0): # when d is 0 both the roots will be equal print("\n roots are equal \n"); root1=root2=-b/(2*a); print("root1=" ,root1, " root2=",root2,); elif(d>0): # roots are real and distinct print("\n roots are real and distinct \n"); root1=(-b+sqrt(d))/(2*a); root2=(-b-sqrt(d))/(2*a); print("root1=" ,root1, " root2=",root2,); # when d is -ve it is not possible to take the squareroot of -ve number, we have to take absolute value of d else: print("\n roots are imaginary \n"); root1=-b/(2*a); root2=sqrt(-d)/(2*a); print("real part= " ,root1, "imaginary part= " ,root2,); Output 1: Please enter first number: 2 Please enter second number: 2 Please enter third number: 2 roots are imaginary real part= -0.5 imaginary part= 0.8660254037844386 Output 2: Please enter first number: 2 Please enter second number: 5 Please enter third number: 1 roots are real and distinct root1= -0.21922359359558485 root2= -2.2807764064044154 Output 3: Please enter first number: 1 Please enter second number: 2 Please enter third number: 1 roots are equal root1= -1.0 root2= -1.0
इन्हें भी देखें।
- while loop
- for loop
- nested loops
- loop control statements (Break, Continue, Pass)
- if statement
- if-else statement
- if-elif statement
- nested if statement
- range() function
- keywords
- Identifiers (names)
- Literals
- Operators
- punctuatorts
Python Programs के लिये यहाँ click करें।