'Having problems with my linear search random number generator [closed]
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 |

