Quick actions

cmd+k|ctrl+k

Navigation

Languages

Kvadratic - Python

Snippet info

Language

Python

Visibility

public

Author

jsonkody

Created

2024-04-02T19:45:29.728702Z

Updated

2024-04-03T09:51:35.610921Z

import math

def kvadratic(a, b, c):
    disc = discrim(a, b, c)
    
    if disc > 0:
        return two_roots(a, b, disc)
    elif disc == 0:
        return one_root(a, b)
    else:
        return "Diskriminant je zaporny, zadne realne koreny."
        
def discrim(a, b, c):
    return b ** 2 - 4 * a * c
    
def two_roots(a, b, disc):
    root1 = (-b + math.sqrt(disc)) / (2 * a)
    root2 = (-b - math.sqrt(disc)) / (2 * a)
    return (root1, root2)

def one_root(a, b):
    return (-b / (2 * a),)

result = kvadratic(2, 6, -20)
print(result)
INFO