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

Time:12-08

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??

CodePudding user response:

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")

CodePudding user response:

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

  • Related