0
My square root equation won't work?
I'm building a very simple calculator, and one thing I would like to add is a square root option. However, my code keeps coming up with this error: Traceback (most recent call last): File "..\Playground\", line 49, in <module> x = list(map(int,x) ValueError: invalid literal for int() with base 10: ' ' The code itself reads: elif "!" in a: x = a.split("!") x = list(map(int,x) y = math.sqrt(x) print (y) In case you need to see the full code: https://code.sololearn.com/c0yoGqbZ5fKx/
1 Respuesta
+ 6
What you get as a result there is a list of two elements - a number and (presumably) an empty string, since:
"16!" ==> split("!") ==> ["16", ""]
So when you try to mapcast int() over an empty string... *BOOM* goes the dynamite!
Robyn Plus you just need to invoke sqrt there in line 50, with no module name, since you imported it directly.
Or just lose it and make the function go:
y = x**0.5