Linear Search using python
<p>Hi I am new to python and I am trying to learn it by writing linear search in python here is the code and this is the code I have written so far. </p>

<pre><code>a = [100]

n = int(raw_input("Enter the no. of elements: "))

print "Enter the elements: "
for i in range(0,n):
    print i

item = int(raw_input("Enter the item to be searched: "))

for i in range(0,10):

    if a[i] == item:
        print "Item ", item, "found at location", i+1
        break;

if i == n:
    print "Item", item, "not found"
</code></pre>

<p>I get a error saying list index out of range, where am I going wrong? </p>

<p>There are some errors in your code, I have tried to rearrange it:</p>

<pre><code>a = []

n = int(raw_input("Enter the no. of elements: "))

print "Enter the elements: "
for i in range(0,n):
    a.append(i)
    print (i)

item = int(raw_input("Enter the item to be searched: "))

found = False
for i in range(0,len(a)):
    if a[i] == item:
        found = True
        print "Item ", item, "found at location", i+1
        break;

if (not found):
    print "Item", item, "not found"
</code></pre>

<p>Please note the following points:</p>

<ol>
<li>Use lists and not arrays: <code>a = []</code></li>
<li>Use the list operations: e.g. <code>a.append(i)</code> to insert an element to a list in the first free slot</li>
<li>Use the boolean values</li>
<li>Discover all the python functionalities ;)</li>
</ol>

python