alnum() function returns true when character is uppercase, lowercase or digit so therefore your code also make temp false if it is a lowercase letter, therefore causing error.
I’ve checked all the 3 conditions still I’m getting wrong ans – Here is the code –
t = int(input())
for _ in range(t):
tags = list(input())
if tags[0] != “<” or tags[1]!="/" or tags[-1]!=’>’:
print(“Error”)
else:
for i in range(2,len(tags)-1):
if tags[i].isalnum() == False:
flag = 0
break
elif tags[i].isalpha() and tags[i].isupper():
flag = 0
break
else:
flag = 1
if flag:
print(“Success”)
else:
print(“Error”)
[simon@simon-laptop][06:52:31]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt
1
</>
[simon@simon-laptop][06:52:37]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt | ./sam_2909-HTMLTAGS.py
Traceback (most recent call last):
File "./sam_2909-HTMLTAGS.py", line 18, in <module>
if flag:
NameError: name 'flag' is not defined
But, I’m not getting any error when I run it on my platform as well as on codechef platform… otherwise it would have given error msg… But i’m getting WA. Also,
this test case gives output as “Error” on codechef platform as well…
hi, actually this was right… i should have defined the flag earlier before use…
But as I was running on jupyter it must have taken the previous cell’s flag and so i didn’t get the error at my side… I corrected it now, and the issue is solved… thanks a lot!!