You are Here: Home

# what is wrong with my binary search code in binary Watch

1. 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
2. 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.

Just quoting in Puddles the Monkey so she can move the thread if needed
Spoiler:
Show
(Original post by Puddles the Monkey)
x

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: April 22, 2016
Today on TSR

### Should I ask for his number?

Discussions on TSR

• Latest
• ## 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
Useful resources

Can you help? Study Help unanswered threadsStudy Help rules and posting guidelines

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest
• ## 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