Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

quadratic formula python

from cmath import sqrt as c_sqrt
from math import sqrt as m_sqrt
import tkinter as tk

# creates and runs an instance of the window
window = tk.Tk()

#makes the size of the widow
window.geometry("600x400")

#sets a title for the screen
window.title("intercode")

# creating a new label and adding a text to the window
new_label=tk.Label(window,text='enter a,b,c quadratic formula
')
new_label.pack()

#creates a entrybox to add words to window
entry_label1=tk.Entry(window)
entry_label1.pack()

entry_label2=tk.Entry(window)
entry_label2.pack()

entry_label3=tk.Entry(window)
entry_label3.pack()
# defines results as string var
results= tk.StringVar(window)



#creating a results label
result_lable=tk.Label(window,textvariable=results)
result_lable.pack()



def callbackfunct():
    a =entry_label1.get()
    b =entry_label2.get()
    c =entry_label3.get()
    try:
        a= float(a)
        b= float(b)
        c= float(c)

    except ValueError:
        results.set("
Enter number.")


    if (b**2-4*a*c) < 0:
        minus = (-b-c_sqrt(b**2-4*a*c))/(2*a)
        plus = (-b+c_sqrt(b**2-4*a*c))/(2*a)
    else:
        minus = (-b-m_sqrt(b**2-4*a*c))/(2*a)
        plus = (-b+m_sqrt(b**2-4*a*c))/(2*a)
        
    # deletes the text in the text box
    entry_label1.delete(0,tk.END)
    entry_label2.delete(0,tk.END)
    entry_label3.delete(0,tk.END)

    var = (f"'B+'   {plus} , 'B-'   {minus}")
    results.set(var)
# creating a button with a command
buttonez = tk.Button(text="Submit", command=callbackfunct)
buttonez.pack()

window.mainloop()
 
PREVIOUS NEXT
Tagged: #quadratic #formula #python
ADD COMMENT
Topic
Name
5+1 =