can somebody help me figure out what is the problem in my code?

Question:

string = input()

for i in string:
    if 'h' in string:
        if 'e' in string+'h':
            if 'll' in string+'h'+'e':
                if 'o' in string+'h'+'e'+'ll':
                    status = True
    else:
        status = False
        
if status:
    print('YES')
else:
    print('NO')

Exception has occurred: NameError
name ‘status’ is not defined

May anyone please help me figure out what is the problem in my code??

Asked By: Nima Abdollahzadeh

||

Answers:

You forgot to define status variable:

string = input()

status = False

for i in string:
    if 'h' in string:
        if 'e' in string+'h':
            if 'll' in string+'h'+'e':
                if 'o' in string+'h'+'e'+'ll':
                    status = True
        
if status:
    print('YES')
else:
    print('NO')

Although, I am not sure I have got logic of your code

Answered By: medelist

In addition to what the other answer pointed out, a few observations:

if 'e' in string+'h':

The +'h' part is pointless – it can’t possibly make any difference, given that h does not equal e.

Also, the for loop is pointless because you never do anything with i – you just do the same comparison repeatedly.

You could just write this whole thing as:

if 'h' in string and 'e' in string and 'll' in string and 'o' in string:
    print("Yes")
else:
    print("No")
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.