0
Why it shows Error
It says int argument must be applied on a string not a list but in the code its not a list its a determined element in the list x=input("Enter claculation OP here\n") OP_list=[] for i in range(0, len(x)): OP_list.append(x[i]) i+=1 if "+" in OP_list: d1=OP_list.index("+") d2=d1+1 result=int(OP_list[:d1])+int(OP_list[d2:]) print(result ) else : print("invalid")
2 Answers
+ 1
Why do you say it's not a list? You implement it as a list not a string since you do OP_list = []. So basically it's a list of strings. Because that's a list, you need to convert it to an actual string. It could be done using str.join().
result=int(''.join(OP_list[:d1]))+int(''.join(OP_list[d2:])) may be what you want.
+ 1
Thank you
I'm still new to python and thought that slicing already convert it to a string but now I understand.
The join method is really helpful