I'm making a function that evaluates maths in a string. First, it takes the string and then converts it to a list.
I tried converting the entire array into an array of integers, but I run into an error when the array looks like this: ["hello",1,"*",2]
as everything isn't a number.
I want to only convert the integers in the array ["1","2","hello","3"]
to integers, so the array becomes [1,2,"hello",3]
That way, I can do maths on the integers and not have them treated as strings, as currently, when I do this:
1 + 2
I get 12
as the output.
I want 3
as the output.
No comments:
Post a Comment