Giải Phương Trình Bậc Hai Sử Dụng Python - Gists · GitHub

Skip to content All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@ASC689561 ASC689561/ptb2.py Created March 5, 2019 02:54 Show Gist options
  • Star () You must be signed in to star a gist
  • Fork () You must be signed in to fork a gist
  • Embed Clone this repository at <script src="https://gist.github.com/ASC689561/7ede0d6a8b8676d553d6be4bcf95b645.js"></script>
  • Save ASC689561/7ede0d6a8b8676d553d6be4bcf95b645 to your computer and use it in GitHub Desktop.
Code Revisions 1 Stars 7 Embed Clone this repository at <script src="https://gist.github.com/ASC689561/7ede0d6a8b8676d553d6be4bcf95b645.js"></script> Save ASC689561/7ede0d6a8b8676d553d6be4bcf95b645 to your computer and use it in GitHub Desktop. Download ZIP Giải phương trình bậc hai sử dụng python Raw ptb2.py This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
from math import sqrt
print("Giải phương trình bậc 2: ax^2 + bx + c = 0")
a = float(input("Nhập a: "))
b = float(input("Nhập b: "))
c = float(input("Nhập c: "))
if a == 0:
if b == 0:
if c == 0:
print("Phương trình vô số nghiệm!")
else:
print("Phương trình vô nghiệm!")
else:
if c == 0:
print("Phương trình có 1 nghiệm x = 0")
else:
print("Phương trình có 1 nghiệm x = ", -c / b)
else:
delta = b ** 2 - 4 * a * c
if delta < 0:
print("Phương trình vô nghiệm!")
elif delta == 0:
print("Phương trình có 1 nghiệm x = ", -b / (2 * a))
else:
print("Phương trình có 2 nghiệm phân biệt!")
print("x1 = ", float((-b - sqrt(delta)) / (2 * a)))
print("x2 = ", float((-b + sqrt(delta)) / (2 * a)))
@kogt2000 Copy link

kogt2000 commented Apr 8, 2020

nice!!

@trinhnv1205 Copy link

trinhnv1205 commented Jun 28, 2020

great

@ThanhTails Copy link

ThanhTails commented May 28, 2021

Quá hay

@Kuunna Copy link

Kuunna commented Jun 24, 2021

nice!!

@sorae42 Copy link

sorae42 commented Nov 13, 2021 edited Loading

the perfect code for every "phương trình bậc hai" question

@thien88828 Copy link

thien88828 commented Nov 14, 2021

Xin cảm ơn!

@thangcamau Copy link

thangcamau commented Jun 7, 2022

cảm ơn bạn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Từ khóa » Giải Pt Bậc 2 Python