![](/img/trans.png)
[英]My python code (Quadratic Equation Solver) is not working, any reason why/
[英]Im making a quadratic equation solver with python and easygui but i cant enter negative numbers. Is there any way around this
import math
import easygui as eg
eg.msgbox("This program solves quadratic equations Enter the values of a, b and c ")
a=eg.integerbox("enter a")
b=eg.integerbox("enter b")
c=eg.integerbox("enter c")
i = b**2-4*a*c
if d < 0:
eg.msgbox("There are no real solutions")
elif i == 0:
x = (-b+math.sqrt(i))/(2*a)
eg.msgbox("heres your solution: "), x
else:
x1 = (-b+math.sqrt(i))/(2*a)
x2 = (-b-math.sqrt(i))/(2*a)
eg.enterbox(msg="you have 2 solutions", default=(x1,x2))
調用時嘗試更改函數integerbox
的默認參數。 具體來說,您要更改為允許負數的那個是lowerbound
。 這是integerbox
的完整定義,因此您可以看到所有參數。
integerbox(msg='', title=' ', default='', lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments)
可以通過以下方法訪問任何平台上的整數的最小值:
import sys
a=eg.integerbox(msg='enter a', lowerbound = -sys.maxint - 1)
可以通過sys.maxint
訪問int的sys.maxint
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.