[Tutor] Problem with "input" in Python 3

Peter Anderson peterjohnanderson at gmail.com
Tue Feb 16 00:18:38 CET 2010

I seem to be having a formatting problem between Thunderbird on my PC
and the mailing list; I am loosing all indentation. The Gmail account
settings on Thunderbird are for plain text and I set the e-mail
content to fixed width text so I'm not sure what's going wrong. I am
trying one last time sending from Gmail (as fixed text).

#   7.2_quadratic2easy.py
#   A program that computes the real roots of a quadratic equation.
#   Bad version using a simple if to avoid program crash
#   This version uses the EasyGUI graphics library
#   See http://easygui.sourceforge.net/ for EasyGUI details

import math
from easygui import *

def main():

    msg = "This program finds the real solutions to a quadratic" + "\n" + \
        "Please enter the three coefficients below."
    title = "quadratic2easy.py"
    fieldNames = ["First coefficient","Second coefficient","Third coefficient"]
    fieldValues = []  # we start with blanks for the values
    fieldValues = multenterbox(msg,title, fieldNames)

    # make sure that none of the fields was left blank
    while 1:
        if fieldValues == None: break
        errmsg = ""
        for i in range(len(fieldNames)):
            if fieldValues[i].strip() == "":
                errmsg = errmsg + ('"%s" is a required field.' % fieldNames[i])
        if errmsg == "": break # no problems found
        fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)

    print("Reply was:", fieldValues)

    a = int(fieldValues[0])
    b = int(fieldValues[1])
    c = int(fieldValues[2])

    discrim = a * a - 4 * b * c
    if discrim >= 0:
        discRoot = math.sqrt(discrim)
        root1 = (-a + discRoot) / (2 * b)
        root2 = (-a - discRoot) / (2 * b)
        message  = "The real solutions to the quadratic equation are "
+ str(root1) + " and " + str(root2)
        msgbox(msg=message, title="quadratic2easy.py",
            ok_button="OK", image=None)


There is nothing more difficult to take in hand, more perilous to
conduct, or more uncertain in its success, than to take the lead in
the introduction of a new order of things -- Niccolo Machiavelli, The
Prince, ch. 6

More information about the Tutor mailing list