In [2]:
temp = 70
if temp < 30:
    print("It's really cold!")
if temp < 65:
    print("It's cold!")
if temp > 100:
    print("It's really hot")
if temp > 85:
    print("It's hot!")
else:
    print("The temperature is fine")


The temperature is fine

In [3]:
words = ['cat', 'window', 'defenestrate']

In [4]:
for w in words:
    print(w)


cat
window
defenestrate

In [5]:
for i in range(len(words)):
    print(words[i])


cat
window
defenestrate

In [6]:
range(len(words))


Out[6]:
range(0, 3)

In [7]:
n = 0
while n < 5:
    n += 1
print(n)


5

In [10]:
j = 0
while j < 5:
    j = 0
    j += 1
print(j)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-10-46c47d8c2d58> in <module>()
      2 while j < 5:
      3     j = 0
----> 4     j += 1
      5 print(j)

KeyboardInterrupt: 

A demonstration of a simple binary search algorithm that first compares the middle term in a list, determines whether the search term is in the first or second half of the list, and then repeats the process until the term is found or a stop condition is met

To summarize: check the middle term. If the value at the middle index equals the search value, return the middle index, otherwise test. If the value is less than the search term, the start index is the middle index + 1 (the next term). If the value is greater than the search term, the end index is the middle index - 1. And the process is repeated until the term is found or the stop condition is met (end index < start index).

The process below searches for the value 6 in the list [1,3,5,7,9]


In [ ]:


In [ ]: