Also, Python has a builtin math module with all kind of useful mathematical functions, e.g. The term under the square root is often called discriminant in English literature. This is of the form: print(f"Nullstelle1= $$ If you want to concatenate strings with variables, you can use an fstring. I have however removed a lot of the casting to floats and strings. The rest of the code is fairly unchanged. I'm not 100% sure why you're checking the type but perhaps your inputs are delicate in some way. Here, we loop over all values in a list and ensure they are NOT all ints: if not all(type(coeff) is int for coeff in ): To loop over several values we can use a generator. Type(val) is int or type(val) is str for example. Now, if you want to check the type of your arguments you can do a simple: Solves quadratic equations of the form ax**2 + bx + c As per PEP8 (python's style guide), I've put your import before the function at the start of the file. My German's not very good so I've just left your comments in apologies if they're now incorrect. I've also added a docstring which briefly explains the function's purpose. I've used the name quadratic_solver and instead of taking input(), it now takes three arguments which are the coefficients. This separates it from anything else you might run, and allows you more control. The first thing I want to do, is to put the code into a function. Print("sorry, geht nicht da eine negative zahl unter der wurzel sein würde") Print("Schnittpunkt mit der Y-Achse ist" " " + O1 + " ") If (U1.isalpha() or I1.isalpha() or O1.isalpha()) is False: Print("ax^2+bx+c ausrechen UwU, Bitte Achte!!! Bei Kommazahlen. Hopefully somebody can help me improve my coding skills. I tried to do some code improvements myself but well whenever I do I fail. The first code I ever wrote, sorry that the prints are in German.
0 Comments
Leave a Reply. |