Python 기본 사항쉬움

이차 방정식의 근 찾기

'2차 방정식의 근 찾기' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

2차 방정식 ax² + bx + c = 0의 계수를 나타내는 세 개의 숫자 a, b, c을 취하고 근을 반환하는 함수 find_roots(a, b, c)을 작성하세요.

2차 공식을 사용하세요: x = (-b ± √(b²-4ac)) / (2a)

반환:

- b²-4ac >= 0(root1 <= root2)인 경우 소수점 이하 2자리로 반올림된 두 개의 부동 소수점(root1, root2)으로 구성된 튜플

- b²-4ac < 0일 때 문자열 'Complex Roots'(판별자가 음수임)

≠ 0이라고 가정합니다.

제약
  • -1000 <= a, b, c <= 1000
  • a != 0

Example 1
Input
find_roots(1, -3, 2)
Output
(1.0, 2.0)
Explanation

x² - 3x + 2 = 0. Discriminant = 9 - 8 = 1. Roots: (3±1)/2 = 2 and 1. Sorted: (1.0, 2.0).

Example 2
Input
find_roots(1, -2, 1)
Output
(1.0, 1.0)
Explanation

x² - 2x + 1 = 0. Discriminant = 4 - 4 = 0. Double root: x = 2/2 = 1.0.

Example 3
Input
find_roots(1, 1, 1)
Output
'Complex Roots'
Explanation

x² + x + 1 = 0. Discriminant = 1 - 4 = -3 < 0. No real roots.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.