[Python] TypeError: '<=' not supported between instances of 'types.GenericAlias' and 'int'

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    my_list = [
    1, 2, 4, 5, 8, 9, 10,
    11, 15, 16, 17, 18, 19, 20,
    21, 22, 26, 27, 28, 29, 30,
    31, 32, 33, 34, 35, 36, 40,
    41, 42, 43, 47, 48, 49, 50
    ]

    # binary search for list of number.

    def binary_search(my_list, users_input):
    low = 0
    high = len(my_list)-1
    while low < high:
    mid = (low + high) // 2
    guess = list[mid]
    if guess == users_input:
    return mid
    if guess < users_input:
    low = mid + 1
    else:
    high = mid - 1
    return None

    # checking if you input is equal to binary input.

    def guess_the_number():
    while True:
    users_position = int(input("Enter the position in the list of number, which you wanted: "))
    if users_position == input_binary_search:
    print("Good job! According to binary search you have guessed correct!")
    break
    elif users_position < input_binary_search:
    print("Your position number is less than the position expected by the binary search")
    else:
    print("Your position number is bigger than the position expected by the binary search")

    # input a numbers from the user and guessing the position of the number in the list.

    print("Welcome. It's my mini game. "
    "Your tasks is:\nInput the number from list"
    "\nGuess the position of this number in this list.")
    print(my_list)

    users_input = int(input("Enter the number from this list: "))
    input_binary_search = binary_search(my_list, users_input)
    guess_the_number()


    I don't know why "'\<=' not supported between instances of 'types.GenericAlias' and 'int'" and how to solve the error? I was trying to rename variables but it didn't help. I'm a beginner in python so I understand that code is bad, but i really want to get to know what is problem.

    Continue reading...

Compartilhe esta Página