Python Forum
math.sqrt / pow() rounding small floats, workaround?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
math.sqrt / pow() rounding small floats, workaround?
#1
Hey everyone, brand new here! I typically find all my answers within a 30min google search. But not this time!
I’m working on a basic Python program, mainly for practice after an intro course covering Python and Java. So I’m kind of a noob, keep that in mind! Anyway, I’ve been adding random functions to it as I have time. It is used for misc circuit troubleshooting (I troubleshoot board assemblies for work). I plan to add any equations I regularly use to it that I possibly can. So here’s my problem.

To solve parallel Impedance, you take a lot of reciprocals of numbers as well as a sqrt of the difference of, well. You’ll see. I decided to split this calculation into chunks, this way I could easily omit values that were not needed and to troubleshoot my code.

Near the end of my calculation, I take the sqrt of a typically small float, like 1.7E-10 ish, then take the reciprocal of the result. Problem is, the result of the sqrt is always 1.0. I’ve tried pow(x, 1/2) and **1/2 as well as sqrt() with no change. I haven’t had time to get this onto my computer yet, however. I’ve coded all of this using IOS with the Python Idle app.

I’ll paste my entire code below to help you help me! Just do me and yourself a favor, if you run the program, know there is really no error handling right now. And once I realized this sqrt problem, I began making it more unstable. So right now, it can only handle to ‘solve’ || impedance if all 3 (Resistance, Xl, Xc) are populated.

Feel free to make any suggestions as well! I’m sure there are a lot of issues this early in development, though. Thank you ahead of time! - RHT

Here’s my terminal for a run as well, followed by actual code. Problem function is:
def parallelZ()

*************************
Enter 0 to Quit
Enter 1 for || Resistance
Enter 2 for xC
Enter 3 for xL
Enter 4 for Z
Enter 5 for || Z
Enter 6 for Phase
*************************
5
====================
Solving || Z
====================
If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.
1
Enter 0 if R NOT present, 1 if present
1
Enter Resistance in Ohms: 100000
Enter 0 if Inductor NOT present, 1 if present
1
Enter Xl in Ohms: 150000
Enter 0 if Capacitor NOT present, 1 if present
1
Enter Xc in Ohms: 200000
Xl: 150000.0
Xc: 200000.0
R: 100000.0
rZ: 1e-10
xlZ: 6.66666666667e-06
xcZ: 5e-06
xlcZ: 2.77777777778e-12
prePreResult: 1.02777777778e-10
preResult: 1.0
Parallel Impedance: 1.0
*************************
Enter 0 to Quit
Enter 1 for || Resistance
Enter 2 for xC
Enter 3 for xL
Enter 4 for Z
Enter 5 for || Z
Enter 6 for Phase
*************************

import math
import decimal # << necessary? will have to determine later on.. 


def solvePhase():
    xOfL = "N/A"
    xOfC = "N/A"
    r = "N/A"
    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")
    haveValues = input()
    if haveValues == 0:
        print("Enter 0 if Inductor NOT present, 1 if present")
        needXl = input()
        if needXl == 1:
            xOfL = lReact(1)
        print("Enter 0 if Capacitor NOT present, 1 if present")
        needXc = input()
        if needXc == 1:
            xOfC = cReact(1)
        print(xOfL)
        print(xOfC)
    r = input("Enter Resistance in Ohms: ")
    if haveValues == 1:
        xOfL = float(input("Enter Xl in Ohms: "))
        xOfC = float(input("Enter Xc in Ohms: "))
    
    if r == "N/A":
        print("Setting R to 1")
        r = 1
    if xOfL == "N/A":
        print("Setting Xl to 1")
        xOfL = 1
    if xOfC == "N/A":
        print("Setting Xc to 1")
        xOfC = 1
    prePhase = math.atan(((xOfL - xOfC) / r))
    phase = math.degrees(prePhase)
    return "Phase: " + str(phase)
    

def lReact(called):
    fHz = input("Enter Frequency in Hz: ")
    lH = input("Enter inductance in H: ")
    fHz = float(fHz)
    lH = float(lH)
    result = (2.0 * math.pi) * fHz * lH
    if called == 1:
        return result
    message = "Inductive Reactance: "
    completeResult = message + str(result)
    return completeResult + " Ohms Z"
    
def cReact(called):
    fHz = input("Enter Frequency in Hz: ")
    cF = input("Enter capacitance in F: ")
    fHz = float(fHz)
    cF = float(cF)
    
    if cF == 0:
        print("Setting cF to 0.0000000001")
        cF = 0.0000000001
    
    result = 1.0 / ((2.0 * math.pi) * fHz * cF)
    if called == 1:
        return result
    message = "Capacitive Reactance: "
    completeResult = message + str(result)
    return completeResult + " Ohms Z"
    

def seriesZ():
    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")
    solveZ = input()
    if solveZ == 0:
        xOfL = lReact()
        xOfC = cReact()
        print(xOfL)
        print(xOfC)
    r = input("Enter Resistance in Ohms: ")
    xl = input("Enter Xl in Ohms: ")
    xc = input("Enter Xc in Ohms: ")
    r = float(r)
    xl = float(xl)
    xc = float(xc)
    result = math.sqrt((r ** 2) + (((xl-xc)**2)))
    message = "Series Impedance: "
    completeResult = message + str(result)
    return completeResult + " Ohms Z"
         
# reciprocal of the sqrt of the reciprocal of the resistance squared plus the difference of the reciprocal of inductive reactance and the reciprocal of capacitive reactance squared.. 
def parallelZ():
# Setting variables to N/A to check
# whether to include in final calc
# If user does not enter value for
# any, N/A will remain in variable
    xOfL = "N/A"
    xOfC = "N/A"
    r = "N/A"
    
# If reactances NOT known, call method
# with argument(1) to return only 
# the reactance (without message)
# Then assign returned value to
# the reactance variable
    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")
    haveValues = input()
    if haveValues == 0:
        print("Enter 0 if Inductor NOT present, 1 if present")
        needXl = input()
        if needXl == 1:
            xOfL = lReact(1)
        print("Enter 0 if Capacitor NOT present, 1 if present")
        needXc = input()
        if needXc == 1:
            xOfC = cReact(1)

# Always asks if R present
    print("Enter 0 if R NOT present, 1 if present")
    needR = input()
    if needR == 1:
        r = float(input("Enter Resistance in Ohms: "))

# If user has reactances, this 
# branch will execute, skipping
# method calls to calculate each
# reactance value
    if haveValues == 1:
        print("Enter 0 if Inductor NOT present, 1 if present")
        needXl = input()
        if needXl == 1:
            xOfL = float(input("Enter Xl in Ohms: "))
        print("Enter 0 if Capacitor NOT present, 1 if present")
        needXc = input()
        if needXc == 1:
            xOfC = float(input("Enter Xc in Ohms: "))
    
    includeR = 1
    includeXOfL = 1
    includeXOfC = 1
    if r == "N/A":
        print("Omitting R")
        includeR = 0
    if xOfL == "N/A":
        print("Omitting Xl")
        includeXOfL = 0
    if xOfC == "N/A":
        print("Omitting Xc")
        includeXOfC = 0
    
    
    print("Xl: " + str(xOfL))
    print("Xc: " + str(xOfC))
    print("R: " + str(r))
    
        
    if includeR == 1:
        rZ = (r **2)**-1
    if includeXOfL == 1:
        xlZ = (xOfL)**-1
    if includeXOfC == 1:
        xcZ = (xOfC)**-1
    print("rZ: " + str(rZ)) # testing
    print("xlZ: " + str(xlZ)) # testing
    print("xcZ: " + str(xcZ)) # testing

    if includeR == 1 and includeXOfL == 1 and includeXOfC == 1:
        xlcZ = float((xlZ - xcZ)**2)
        prePreResult = float((rZ + xlcZ))
        print("xlcZ: " + str(xlcZ)) # testing 
        print("prePreResult: " + str(prePreResult)) # testing
        preResult = pow(prePreResult, 1/2)
        print("preResult: " + str(preResult)) # testing
        result = float((preResult)**-1)
        
        message = "Parallel Impedance: "
        completeResult = message + str(result)
        return completeResult
    

def parallelResistance():
    resistor1 = input("Enter 1st resistance: ")
    resistor1 = float(resistor1)
    resistor2 = input("Enter 2nd resistance: ")
    resistor2 = float(resistor2)
    r1 = resistor1
    r2 = resistor2
    result = (1.0 / r1) + (1.0 / r2)
    result = 1.0 / result
    return result

def mainMenu():
    print("*************************")
    print("Enter 0 to Quit")
    print("Enter 1 for || Resistance")
    print("Enter 2 for xC")
    print("Enter 3 for xL")
    print("Enter 4 for Z")
    print("Enter 5 for || Z")
    print("Enter 6 for Phase")
    print("*************************")
    choice = input()
    if choice == 0:
        return choice
    if choice == 1:
        return choice
    if choice == 2:
        return choice
    if choice == 3:
        return choice
    if choice == 4:
        return choice
    if choice == 5:
        return choice
    if choice == 6:
        return choice
    

# Main Code #
programIsTerminated = 0
while programIsTerminated == 0:
    menuChoice = mainMenu()
    
    if menuChoice == 0:
        print("====================")
        print("Program Terminated")
        print("====================")
        # programIsTerminated = 1
        break
    if menuChoice == 1:
        print("====================")
        print("Solving || Resistance")
        print("====================")
        print(parallelResistance())
        continue
    if menuChoice == 2:
        print("====================")
        print("Solving Xc")
        print("====================")
        print(cReact())
        continue
    if menuChoice == 3:
        print("====================")
        print("Solving Xl")
        print("====================")
        print(lReact())
        continue
    if menuChoice == 4:
        print("====================")
        print("Solving Z")
        print("====================")
        print(seriesZ())
        continue
    if menuChoice == 5:
        print("====================")
        print("Solving || Z")
        print("====================")
        print(parallelZ())
        continue
    if menuChoice == 6:
        print("====================")
        print("Solving Phase")
        print("====================")
        print(solvePhase())
        continue
    else:
        print("====================")
        print("Please enter a VALID choice.")
        print("====================")
        continue
        
# print("Program Terminated")
Reply
#2
The only thing I see is that you may be running the code with the python 2 interpreter instead of python 3. In python 2 the value of 1/2 is 0. It is better to use python 3 of course, but you can still use python 2 if you add this at the top of the file
from __future__ import (absolute_import, division,
                        print_function, unicode_literals)
the import of __future__.division ensures that 1/2 is 0.5 in python 2.

Here is some extra code for christmas
class B:
    h, v, ul, ur, ll, lr = [chr(0x2550 + x) for x in (0, 1, 4, 7, 10, 13)]
    
def boxed(s, indent=0):
    def boxed(s, indent):
        size = len(s) + 2
        t = ' ' * indent if indent else ''
        yield "{}{}{}{}\n".format(t, B.ul, B.h * size, B.ur)
        yield "{}{} {} {}\n".format(t, B.v, s, B.v)
        yield "{}{}{}{}".format(t, B.ll, B.h * size, B.lr)
    return ''.join(boxed(s, indent))

print(boxed('Hello World', indent=8))
Output:
╔═════════════╗ ║ Hello World ║ ╚═════════════╝
Reply
#3
Ah, of course it’s something that simple! You’re right, Python2IDE. I have 3 everywhere else, but reviews for Python3IDE for IOS were terrible for some reason, so I’m sitting with 2 for now.

The 1/2 to 0.5 code worked like a charm!! Thanks! Now I just need to go through and remove all the code I added to help isolate the issue haha.

The Xmas present doesn’t seem to like Python2IDE :(. I’ll be moving this to my computer before I waste more time on issues that Py3 would fix!

Again, thanks a ton! You have no idea how good it feels to see an actual impedance value returned after so many results of “Yea, the || impedance is 1.0 Ohms, obviously. ...”

Here’s what I’m getting from just a direct copy/paste of the formatting code you provided.(Py2)

Error:
Traceback (most recent call last): File "/var/mobile/Containers/Data/Application/B66AD966-265E-4376-B2B9-1507C9F6D358/Documents/noname (2).py", line 8, in <module> class B: File "/var/mobile/Containers/Data/Application/B66AD966-265E-4376-B2B9-1507C9F6D358/Documents/noname (2).py", line 9, in B h, v, ul, ur, ll, lr = [chr(0x2550 + x) for x in (0, 1, 4, 7, 10, 13)] ValueError: chr() arg not in range(256)
I thought maybe [chr(0x2550 + x) had an extra 0 appended causing the issue, but removing the 0 gave me the same error. But no worries, it likely works great in Py3. Will definitely take that formatting over my manual borders :D
Merry Christmas!
Reply
#4
Python 2 Wrote:ValueError: chr() arg not in range(256)
In python 2, use unichr() instead of chr(), but better forget about it and use python 3!
Reply
#5
(Dec-22-2018, 06:08 PM)Gribouillis Wrote: but better forget about it and use python 3!

Gribouillis is right. Support for Python before 3.0 ends in 374 days.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
Thanks! Got 4 new Python3 IDE’s. The first one I tried out seems to work fine.

However, this may be the apps fault but the box code you gifted me seems to have a minor bug.
The middle right side border is shifted left, only a space or two from the contents. This is supposedly Py3 btw.

Output:
╔═════════════╗ ║ Hello World ║ ╚═════════════╝
Actually, looks fine when I preview it here LOL. I’ll just try this on my computer :).

Thanks for the help, info and code! If you get bored, feel free to make any improvements or other suggestions to the code I posted. I tried to keep things simple but definitely wouldn’t mind seeing a more efficient/advanced method, pun intended.

Well... On my computer now, emailed the code to myself and pasted into IDLE Python 3.7.

When executed, my def mainMenu(): function is called, but seems to ALWAYS return a value that is unexpected. For example, if I enter '0' my code executes the 'else' block, indicating '0' was not returned. Same for any input that should result in a valid choice. I will likely have time to investigate this later today, but if anybody has any ideas, I'll include an exact copy of my code below. This new version just includes minor changes to the code I originally posted, like the class Gribouillis provided and I commented out a few print functions I had for troubleshooting.

A quick overview of what my code should do:
While loop will Call mainMenu() # This displays a menu with choices 0, 1, 2, 3, 4, 5, 6
Prompt for input and save this to choice
If choice == 1 || 2 || 3 || 4 || 5 || 6, it will return choice
Else, it will return 999
If the returned value is == 1 || 2 || 3 || 4 || 5 || 6, the corresponding branch executes, function is called
Else, prompt to enter a VALID choice is displayed, continue

Again, when I run this, Else always executes. Any help is appreciated!

from __future__ import (absolute_import, division,

                        print_function, unicode_literals)

# ^^ this given by Gribouillis(Python forums)


import math

import decimal # << necessary? will have to determine later on.. 



# class given by Gribouillis(Python forums)

class B:

    h, v, ul, ur, ll, lr = [chr(0x2550 + x) for x in (0, 1, 4, 7, 10, 13)]

     

def boxed(s, indent=0):

    def boxed(s, indent):

        size = len(s) + 2

        t = ' ' * indent if indent else ''

        yield "{}{}{}{}\n".format(t, B.ul, B.h * size, B.ur)

        yield "{}{} {} {}\n".format(t, B.v, s, B.v)

        yield "{}{}{}{}".format(t, B.ll, B.h * size, B.lr)

    return ''.join(boxed(s, indent))

 

print(boxed('Hello World', indent=0))

# end of class, thanks Gribouillis.





def solvePhase():

    xOfL = "N/A"

    xOfC = "N/A"

    r = "N/A"

    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")

    haveValues = input()

    if haveValues == 0:

        print("Enter 0 if Inductor NOT present, 1 if present")

        needXl = input()

        if needXl == 1:

            xOfL = lReact(1)

        print("Enter 0 if Capacitor NOT present, 1 if present")

        needXc = input()

        if needXc == 1:

            xOfC = cReact(1)

        print(xOfL)

        print(xOfC)

    r = input("Enter Resistance in Ohms: ")

    if haveValues == 1:

        xOfL = float(input("Enter Xl in Ohms: "))

        xOfC = float(input("Enter Xc in Ohms: "))

    

    if r == "N/A":

        print("Setting R to 1")

        r = 1

    if xOfL == "N/A":

        print("Setting Xl to 1")

        xOfL = 1

    if xOfC == "N/A":

        print("Setting Xc to 1")

        xOfC = 1

    prePhase = math.atan(((xOfL - xOfC) / r))

    phase = math.degrees(prePhase)

    return "Phase: " + str(phase)

    



def lReact(called):

    fHz = input("Enter Frequency in Hz: ")

    lH = input("Enter inductance in H: ")

    fHz = float(fHz)

    lH = float(lH)

    result = (2.0 * math.pi) * fHz * lH

    if called == 1:

        return result

    message = "Inductive Reactance: "

    completeResult = message + str(result)

    return completeResult + " Ohms Z"

    

def cReact(called):

    fHz = input("Enter Frequency in Hz: ")

    cF = input("Enter capacitance in F: ")

    fHz = float(fHz)

    cF = float(cF)

    

    if cF == 0:

        print("Setting cF to 0.0000000001")

        cF = 0.0000000001

    

    result = 1.0 / ((2.0 * math.pi) * fHz * cF)

    if called == 1:

        return result

    message = "Capacitive Reactance: "

    completeResult = message + str(result)

    return completeResult + " Ohms Z"

    



def seriesZ():

    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")

    solveZ = input()

    if solveZ == 0:

        xOfL = lReact()

        xOfC = cReact()

        print(xOfL)

        print(xOfC)

    r = input("Enter Resistance in Ohms: ")

    xl = input("Enter Xl in Ohms: ")

    xc = input("Enter Xc in Ohms: ")

    r = float(r)

    xl = float(xl)

    xc = float(xc)

    result = math.sqrt((r ** 2) + (((xl-xc)**2)))

    message = "Series Impedance: "

    completeResult = message + str(result)

    return completeResult + " Ohms Z"

         

# reciprocal of the sqrt of the reciprocal of the resistance squared plus the difference of the reciprocal of inductive reactance and the reciprocal of capacitive reactance squared.. 

def parallelZ():

# Setting variables to N/A to check

# whether to include in final calc

# If user does not enter value for

# any, N/A will remain in variable

    xOfL = "N/A"

    xOfC = "N/A"

    r = "N/A"

    

# If reactances NOT known, call method

# with argument(1) to return only 

# the reactance (without message)

# Then assign returned value to

# the reactance variable

    print("If you don't have R, Xl, Xc, enter 0 to acquire these before continuing. Otherwise, enter 1.")

    haveValues = input()

    if haveValues == 0:

        print("Enter 0 if Inductor NOT present, 1 if present")

        needXl = input()

        if needXl == 1:

            xOfL = lReact(1)

        print("Enter 0 if Capacitor NOT present, 1 if present")

        needXc = input()

        if needXc == 1:

            xOfC = cReact(1)



# Always asks if R present

    print("Enter 0 if R NOT present, 1 if present")

    needR = input()

    if needR == 1:

        r = float(input("Enter Resistance in Ohms: "))



# If user has reactances, this 

# branch will execute, skipping

# method calls to calculate each

# reactance value

    if haveValues == 1:

        print("Enter 0 if Inductor NOT present, 1 if present")

        needXl = input()

        if needXl == 1:

            xOfL = float(input("Enter Xl in Ohms: "))

        print("Enter 0 if Capacitor NOT present, 1 if present")

        needXc = input()

        if needXc == 1:

            xOfC = float(input("Enter Xc in Ohms: "))

    

    includeR = 1

    includeXOfL = 1

    includeXOfC = 1

    if r == "N/A":

        print("Omitting R")

        includeR = 0

    if xOfL == "N/A":

        print("Omitting Xl")

        includeXOfL = 0

    if xOfC == "N/A":

        print("Omitting Xc")

        includeXOfC = 0

    

    

    print("Xl: " + str(xOfL))

    print("Xc: " + str(xOfC))

    print("R: " + str(r))

    

        

    if includeR == 1:

        rZ = (r **2)**-1

    if includeXOfL == 1:

        xlZ = (xOfL)**-1

    if includeXOfC == 1:

        xcZ = (xOfC)**-1

    print("rZ: " + str(rZ))

    print("xlZ: " + str(xlZ))

    print("xcZ: " + str(xcZ))



    if includeR == 1 and includeXOfL == 1 and includeXOfC == 1:

        xlcZ = float((xlZ - xcZ)**2)

        prePreResult = float((rZ + xlcZ))

#         print("xlcZ: " + str(xlcZ))

#         print("prePreResult: " + str(prePreResult))

        preResult = (prePreResult)**(1/2)

#         print("preResult: " + str(preResult))

        result = ((preResult)**-1)

        

        message = "Parallel Impedance: "

        completeResult = message + str(result)

        return completeResult

    



def parallelResistance():

    resistor1 = input("Enter 1st resistance: ")

    resistor1 = float(resistor1)

    resistor2 = input("Enter 2nd resistance: ")

    resistor2 = float(resistor2)

    r1 = resistor1

    r2 = resistor2

    result = (1.0 / r1) + (1.0 / r2)

    result = 1.0 / result

    return result



def mainMenu():

    print("*************************")

    print("Enter 0 to Quit")

    print("Enter 1 for || Resistance")

    print("Enter 2 for xC")

    print("Enter 3 for xL")

    print("Enter 4 for Z")

    print("Enter 5 for || Z")

    print("Enter 6 for Phase")

    print("*************************")

    choice = input()

    if choice == 0:

        return choice

    if choice == 1:

        return choice

    if choice == 2:

        return choice

    if choice == 3:

        return choice

    if choice == 4:

        return choice

    if choice == 5:

        return choice

    if choice == 6:

        return choice

    

    return 999



# Main Code #

programIsTerminated = 0

while programIsTerminated == 0:

    menuChoice = mainMenu()

    

    #print(boxed('', indent=0))

    

    if menuChoice == 0:

        #print("====================")

        print("Program Terminated")

        #print("====================")

        # programIsTerminated = 1

        break

    if menuChoice == 1:

        print("====================")

        print("Solving || Resistance")

        print("====================")

        print(parallelResistance())

        continue

    if menuChoice == 2:

        print("====================")

        print("Solving Xc")

        print("====================")

        print(cReact())

        continue

    if menuChoice == 3:

        print("====================")

        print("Solving Xl")

        print("====================")

        print(lReact())

        continue

    if menuChoice == 4:

        print("====================")

        print("Solving Z")

        print("====================")

        print(seriesZ())

        continue

    if menuChoice == 5:

        print("====================")

        print("Solving || Z")

        print("====================")

        print(parallelZ())

        continue

    if menuChoice == 6:

        print("====================")

        print("Solving Phase")

        print("====================")

        print(solvePhase())

        continue

    else:

        print("====================")

        print("Please enter a VALID choice.")

        print("====================")

        continue

        

# print("Program Terminated")
Reply
#7
The input() function changed from python 2 to 3. In python 3, input() returns a string, it means that choice is no longer the integer 1 but the string '1'. This is why choice == 1 fails. You need to adapt the code.

Here is how you can write mainMenu() and the end of the code
def mainMenu():
    print("""\
*************************
Enter 0 to Quit
Enter 1 for || Resistance
Enter 2 for xC
Enter 3 for xL
Enter 4 for Z
Enter 5 for || Z
Enter 6 for Phase
*************************""")
    try:
        choice = int(input())
    except ValueError:
        return None
    return choice if (0 <= choice <= 6) else None

# Main Code #
 
programIsTerminated = False
 
while not programIsTerminated:
    menuChoice = mainMenu()
    if menuChoice == 0:
        print(boxed("Program Terminated"))
        programIsTerminated = True
    elif menuChoice == 1:
        print(boxed("Solving || Resistance"))
        print(parallelResistance())
    elif menuChoice == 2:
        print(boxed("Solving Xc"))
        print(cReact())
    elif menuChoice == 3:
        print(boxed("Solving Xl"))
        print(lReact())
    elif menuChoice == 4:
        print(boxed("Solving Z"))
        print(seriesZ())
    elif menuChoice == 5:
        print(boxed("Solving || Z"))
        print(parallelZ())
    elif menuChoice == 6:
        print(boxed("Solving Phase"))
        print(solvePhase())
    else:
        print(boxed("Please enter a VALID choice."))
Reply
#8
Grr. I can't believe how much I've forgotten in only ~ 2 months of not writing in Python. I should have known this haha.

Also, had no idea that:
print("""\ x """)
was even a thing that I could do. That's awesome, much more efficient.

Thanks for the revision! I see you not only solved my problem, but also corrected my habit of "if, if, if, if-ing" and not to mention, you boxed all of it for me!

Thanks for all the things! haha. Saved me like 2 hours of trial-error and you even got my while not programIsTerminated to work. I basically just gave up on that haha.

Thanks again, you'll likely see more of me around here!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  When is it safe to compare (==) two floats? Radical 4 711 Nov-12-2023, 11:53 AM
Last Post: PyDan
  need help rounding joseph202020 7 1,321 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  from numpy array to csv - rounding SchroedingersLion 6 2,171 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  math.log versus math.log10 stevendaprano 10 2,415 May-23-2022, 08:59 PM
Last Post: jefsummers
  floats 2 decimals rwahdan 3 1,622 Dec-19-2021, 10:30 PM
Last Post: snippsat
  Random data generation sum to 1 by rounding juniorcoder 9 3,422 Oct-20-2021, 03:36 PM
Last Post: deanhystad
  Rounding issue kmll 1 1,417 Oct-08-2021, 10:35 AM
Last Post: Yoriz
  Not rounding to desired decimal places? pprod 2 2,560 Mar-05-2021, 11:11 AM
Last Post: pprod
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,771 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Decimal Rounding error project_science 4 2,760 Jan-06-2021, 03:14 PM
Last Post: project_science

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020