+ 1

Else statement not working Python

A part of the program tests if the variable is int or string. If it's a string do this, else do that. Even though I seperated them, it still runs the both statements. I entered a string, but it tries to loop over range(String) which causes error. Why won't the else statement work? Line 34 https://code.sololearn.com/crAWjqQy8qiF/?ref=app

7th Aug 2020, 9:18 PM
Clueless Coder
Clueless Coder - avatar
1 ответ
+ 5
Instead checking type(statement)=="str" ,check for the string the following way, if isinstance(statement,str):
7th Aug 2020, 9:23 PM
Abhay
Abhay - avatar