Advertisement
xavicano

Untitled

Aug 20th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import  random
  2. from random import randint
  3.  
  4. def random_char(num_of_char):
  5.     charset="".join(chr(x) for x in range(48,122)) 
  6.     #return charset[random.randint(0,74)]
  7.     password="".join(charset[random.randint(0,73)] for y in range(num_of_char))
  8.     return password
  9.    
  10. ##Example 1 - A while loop
  11. #position = 0
  12. #while position < len(sequence):
  13.     #print(sequence[position], "is at position", str(position))
  14.     #position += 1
  15.  
  16.  
  17. ##Example 2 - A for loop over a range
  18. #for position in range(len(sequence)):
  19.     #print(sequence[position], "is at position", str(position))
  20.  
  21.  
  22. ##Example 3 - The enumerate function
  23. #for position, item in enumerate(sequence):
  24.     #print(item, "is at position", position)
  25. def search_for_enumerate(list_to_search, target, is_sorted):
  26.     for position, item in enumerate(list_to_search):
  27.         if target==item:
  28.             print(target, "is at position", position)
  29.         elif is_sorted and position > len(list_to_search):
  30.             print (" Taget not found in sorted list")
  31.             return False           
  32.         elif position >= len(list_to_search)-1:
  33.             print (" Taget not found in unsorted list")
  34.             return False
  35.     return True
  36.    
  37.        
  38.  
  39.  
  40. list_of_num = [randint(0,50) for i in range(10)]
  41. print(list_of_num)
  42. list_of_char = random_char(50)
  43. print(list_of_char)
  44.    
  45. search_for_enumerate(list_of_num, 50, False)   
  46.  
  47. search_for_enumerate(list_of_char, "a", False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement