簡體   English   中英

我用python和easygui制作二次方程求解器,但我不能輸入負數。 有沒有辦法解決

[英]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") 

當我嘗試輸入負數或超過99的數字時,整數框不會讓我,有沒有辦法解決這個問題

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM