Skip to content

Instantly share code, notes, and snippets.

@KHerb
Created June 17, 2016 14:16
Show Gist options
  • Save KHerb/72ba9637c18300fee63d9eb024657ac9 to your computer and use it in GitHub Desktop.
Save KHerb/72ba9637c18300fee63d9eb024657ac9 to your computer and use it in GitHub Desktop.
Element Search
import random
lst = [i for i in range(random.randrange(0,1000))]
n = int(raw_input("Enter a number to see if it's in the list range: "))
def elementsearch(lst,n):
if n in lst:
return True
else:
return False
if elementsearch(lst,n) == True:
print "%d is in the list range" % n
if elementsearch(lst,n) == False:
print "%d is NOT in the list range" % n
@Raj39120
Copy link

Raj39120 commented May 4, 2020

user_input = input("Enter a list of numbers from least to greatest over here: ")
user_input_2 = input("Enter the number you want to check to see if it's in the above list over here: ")
if user_input_2 in user_input:
print("This number is in the list you entered.")
if user_input_2 not in user_input:
print("This number is not in the list you entered.")

another solution with user input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment