I’m relatively new to Python. I’m trying to make a Quadratic Equation calculator, including negative number square roots (using cmath), and to do that I’ve made a few functions to get my answers and make them the way I want them to be. Everything was working pretty well but for some reason when I activated the code I got the value inputs correctly, but then infinite blank input lines. I figured out this happened when the return function of the remove_undesirables function I made was being executed. Why is this happening?
Code:
def quadratic_solver(a, b, c):
from cmath import sqrt
a = float(a)
b = float(b)
c = float(c)
answer1 = (b + sqrt(b ** 2 - (4 * a * c))) / (2 * a)
answer2 = (b - sqrt(b ** 2 - (4 * a * c))) / (2 * a)
return [f"{answer1}", f"{answer2}"]
a_value = input("a value: ")
b_value = input("b value: ")
c_value = input("c value: ")
answers = quadratic_solver(a_value, b_value, c_value)
def is_real(number):
for type_n in number:
type_complex = complex(type_n)
if type_complex - type_complex.real == 0j:
return True
else:
return False
remove_in_real = ["(", ")", "+0j"]
remove_in_complex_or_imaginary = ["(", ")", "j"]
def remove_undesirables(remove_in, condition, undesirables_condition, undesirables_else):
for type_n in remove_in:
if condition:
for item in undesirables_condition:
type_new = str(type_n).replace(item, "")
else:
for item in undesirables_else:
type_new = str(type_n).replace(item, "")
type_new.split("+")
remove_in_new = remove_in.append(type_new)
return remove_in_new
done = remove_undesirables(answers, is_real(answers), remove_in_real, remove_in_complex_or_imaginary)
I’ve attached a picture of the blank input lines.
(I don’t know if it has anything to do with anything, sometimes when I activate the program there are some errors for a split second and then they disappear and it works.)