TypeError: list indices must be integers, not float

前端 未结 4 597
感情败类
感情败类 2021-02-05 02:47

I have a python 3.x program that is producing an error:

def main():
    names = [\'Ava Fischer\', \'Bob White\', \'Chris Rich\', \'Danielle Porter\',
                    


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 03:42

    Kinda late to the party but you could also use:

    middle = int((first + last) / 2)

    In any case why you are getting your error is perfectly explained in RocketDonkey answer.

    For your code to work you should also set:

    position = binary_search(names, entered)
    

    as Hugo Ferreira mentioned.

    Also check this question: What is the difference between '/' and '//' when used for division?

提交回复
热议问题