Advertisement
scarygarey

linear_sorted

Jan 14th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import random
  2. listnums = []
  3. for i in range(0,50): #will populate 50 random numbers
  4. listnums.append(random.randint(0,100)) # will select 50 random numbers between 1-100)
  5. listnums.sort()
  6. print(listnums) #the numbers randomly selected will appear below
  7.  
  8. print("what integer are you searching for between 1-100?")
  9. search = int(input()) #requires user to input a number
  10.  
  11. found = False
  12.  
  13. for i in range (0,len(listnums)): # this checks from the first position in the random number list
  14. if listnums[i] == search: #if number entered is found in the list
  15. found = True
  16.  
  17. if found == True:
  18. print("this integer is in the list") #foundl
  19. else:
  20. print("this integer is not in the list") #not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement