'Having problems with my linear search random number generator [closed]

I have no clue why this doesn't work, it's a random number generator from 1-100 which generates 50 numbers then asks for user input to see if that number is contained in the list. I don't see why this is a syntax error:



Solution 1:[1]

You have to indent correctly. Instead of:

if num in mylist:
    print("The list is:", mylist)
position = LinearSearch(mylist, num)
print("element", 'num, is at position', position)

else:
    print("Your number was not in the list ;-;")

You want:

if num in mylist:
    print("The list is:", mylist)
    position = LinearSearch(mylist, num) #notice the indention
    print("element", 'num, is at position', position) #notice the indention

else:
    print("Your number was not in the list ;-;"

This tells python that the else goes with the if since the other lines are not "in between" them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eli Harold