Problem with if design



  • def easy(utext):
        convert_to_list = list(utext)
        print(convert_to_list)
        lenght = len(convert_to_list)
        s = abc[::-1]
        for i in convert_to_list:
            a = 0
            if convert_to_list[:a] == abc[:a]:
                new_generate_pass = []
                #s = abc[::-1]
                new_generate_pass.append(s[a])
                print (new_generate_pass)
            a = a + 1  
    utext = input("Введите ваше слово: ")
    

    Actually, it's kind of a problem, thinking when we get in if

    Two lists should compare their index values and if there are the same letters "a" (for example) the code should be performed below. But whether there's a match or not, he's doing everything he describes if



  • this code.

    a = 0
    if convert_to_list[:a] == abc[:a]
    

    means

    if convert_to_list[:0] == abc[:0]
    

    a list[:0] - is a zero-size list (from 0 to 0 of the element not included)

    You. TOTAL (a) Before verification is set to 0) check the cuts of two lists of which 0 - of course they are always equal

    I suspect your code was supposed to look like:

    a = 0
    for i in convert_to_list:
        if convert_to_list[a] == abc[a]:
            new_generate_pass = []
            #s = abc[::-1]
            new_generate_pass.append(s[a])
            print (new_generate_pass)
        a = a + 1  
    

    Yeah, and there's a question about what's going on inside. if:

    You're making a new list. new_generate_pass, put one element in it. s[a] and put it on the screen.

    that's because of what's inside. if You're making a list, you're basically never gonna have one more element, and you're not gonna save it.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2