My square root equation won't work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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/

10th Apr 2018, 6:31 PM
Robyn
1 Answer
+ 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
10th Apr 2018, 6:42 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar