Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    1
    ReputationRep:
    the code is quite complete but im running this error:
    "Traceback (most recent call last):
    File "G:/shsb/Computer science/Binary search.py", line 29, in <module>
    if alpha[midpoint] < find:
    TypeError: list indices must be integers or slices, not float"


    this is the code that im running
    alpha = ["a","b","c","d","e","f","g","h", "i","j"]
    find = "b"
    midpoint = int(len(alpha)//2)
    lowerBound = 0
    upperBound = len(alpha)-1
    foundValue = False

    while foundValue == False:
    if find == alpha[midpoint]:
    foundValue = True
    print ("item found at position " ,midpoint)
    break
    if find == alpha[upperBound]:
    foundValue = True
    print ("item found at position " ,upperBound)
    break
    if find == alpha[lowerBound]:
    foundValue = True
    print ("item found at position " ,lowerBound)
    break
    else:
    while alpha [midpoint] != find:
    while alpha[lowerBound] != find:
    while alpha[upperBound]!= find:
    if alpha[midpoint] < find:
    upperBound = midpoint
    midpoint = (upperBound-lowerBound)/2
    else:
    lowerBound = midpoint
    midpoint = ((upperBound-lowerBound)/2)+lowerBound


    if any one code help it would be much appreciated
    •  Official Rep
    Offline

    15
    ReputationRep:
     Official Rep
    Sorry you've not had any responses about this. Are you sure you've posted in the right place? Here's a link to our subject forum which should help get you more responses if you post there.

    You can also find the Exam Thread list for A-levels here and GCSE here. :dumbells:


    Just quoting in Puddles the Monkey so she can move the thread if needed
    Spoiler:
    Show
    (Original post by Puddles the Monkey)
    x
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Has a teacher ever helped you cheat?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Write a reply...
    Reply
    Hide
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.