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()
roots = ( -b + sqrt(b ^ 2 - 4 * a *c) ) / (2 * a) , ( -b - sqrt(b ^ 2 - 4 * a *c) ) / (2 * a)
from math import sqrt
def quadratic(a, b, c):
x1 = -b / (2*a)
x2 = sqrt(b**2 - 4*a*c) / (2*a)
return (x1 + x2), (x1 - x2)
print ("ax2 + bx + c = 0")
a = float(input("a: "))
b = float(input("b: "))
c = float(input("c: "))
delta = (b**2) - (4*a*c)
answers = []
numerator = [-b + delta**0.5, -b - delta**0.5]
denominator= 2 * a
for i in range(2):
ans = numerator[i] / denominator
answers.append(ans)
print (answers)
(-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)
ax2 + bx + c = 0, where
a, b and c are real numbers and
a ≠ 0
def square(n):
num=n
newnum=n*n
return newnum