gpt4 book ai didi

python - ** 或 pow() 不支持的操作数类型 : 'method' and 'int'

转载 作者:行者123 更新时间:2023-11-30 22:49:48 26 4
gpt4 key购买 nike

from tkinter import *
import math
import sys

def quit():
root.destroy()

def a_b_c():
print_a()
print_b()
print_c()
calculation()
return

def print_a():
get_a = a.get()
printing_a = Label(root, text=get_a).grid(row=8, column=1)
return

def print_b():
get_b = b.get()
printing_b =Label(root, text=get_b).grid(row=12, column=1)
return

def print_c():
get_c = c.get()
printing_c =Label(root, text=get_c).grid(row=16, column=1)
return


root = Tk()
a = StringVar()
b = StringVar()
c = StringVar()

root.title('Solving Quadratic Equations')

quit_b = Button(root, text="quit",command=quit).grid(row=1, column=1)
go_b = Button(root, text="go", command=a_b_c).grid(row=1, column=2)
welcome = Label(root, text="Welcome to Solving Quadratic Equations with GlaDOS",font=("Helvetica",13))
welcome.grid(row=2, column=1)


instructions = Label(root, text="So how do i use this program? is what you may ask yourself. So, for example, \n you have the equation 2x^2+5x+8=0. So the 2x^2 is a but you don't put the\n whole thing in you just but the 2 from the start in. The next thing is b\n in this case b = 5 and c is equal to 8. Once you have all you number in the boxes \n hit the go button. Remember you don't need the x's. ", font=("Helvetica",11))
instructions.grid(row=3, column=1)

line = Label(root, text="************************************************************************************************************").grid(row=4, column=1)

input_a = Label(root, text="Pls input A here", font=("Helvetica",11)).grid(row=6, column=1)
entry_a = Entry(root,textvariable=a).grid(row=7,column=1)

line = Label(root, text="************************************************************************************************************").grid(row=9, column=1)

input_b = Label(root, text="Pls input B here", font=("Helvetica",11)).grid(row=10, column=1)
entry_b = Entry(root,textvariable=b).grid(row=11,column=1)

line = Label(root, text="*************************************************************************************************************").grid(row=13, column=1)
input_c = Label(root, text="Pls input C here", font=("Helvetica",11)).grid(row=14, column=1)
entry_c = Entry(root,textvariable=c).grid(row=15,column=1)

two_a = a.get
two_b = b.get
two_c = c.get

d = two_b**2-4*two_a*two_c
def calculation():
if d < 0:
no_solution = Label(root, text="This equation has no real solution").grid(row=19, column=1)
elif d == 0:
x = (-two_b+math.sqrt(two_b**2-4*two_a*two_c))/2*two_a
one_solution = Label(root, text="This equation has one solutions: {}".format(x)).grid(row=20, column=1)
else:
x1 = (-two_b+math.sqrt((two_b**2)-(4*(two_a*two_c))))/(2*two_a)
x1 = (-two_b-math.sqrt((two_b**2)-(4*(two_a*two_c))))/(2*two_a)
two_solution= label(root, text="This equation has two solutions: {} or {} ".format(x1,x2)).grid(row=21, colum=1)

root.mainloop()

为什么它说 ** 或 pow() 不支持操作数类型:方法或 int?有人可以帮我改变它,以便它可以在学校使用,而老师无法帮助我。我正在尝试制作一个程序来帮助您解决二次方程和底部的部分不工作(定义计算)谢谢你帮助我:)

最佳答案

您正在分配一些值:

two_a = a.get
two_b = b.get
two_c = c.get

然后进行计算:

d = two_b**2-...

但是,a.get 是一种检索该StringVar 值的方法。要实际调用它并检索值,您必须......好吧,用括号调用它:

two_a = a.get()

此外,您还将获得字符串。使用 intfloat 将它们转换为整数或 float :

two_a = int(a.get())
# or:
two_a = float(a.get())

然后你的算术将按预期工作。

关于python - ** 或 pow() 不支持的操作数类型 : 'method' and 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39584033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com