Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import randint
- def random_char(num_of_char):
- charset="".join(chr(x) for x in range(48,122))
- #return charset[random.randint(0,74)]
- password="".join(charset[random.randint(0,73)] for y in range(num_of_char))
- return password
- ##Example 1 - A while loop
- #position = 0
- #while position < len(sequence):
- #print(sequence[position], "is at position", str(position))
- #position += 1
- ##Example 2 - A for loop over a range
- #for position in range(len(sequence)):
- #print(sequence[position], "is at position", str(position))
- ##Example 3 - The enumerate function
- #for position, item in enumerate(sequence):
- #print(item, "is at position", position)
- def search_for_enumerate(list_to_search, target, is_sorted):
- for position, item in enumerate(list_to_search):
- if target==item:
- print(target, "is at position", position)
- elif is_sorted and position > len(list_to_search):
- print (" Taget not found in sorted list")
- return False
- elif position >= len(list_to_search)-1:
- print (" Taget not found in unsorted list")
- return False
- return True
- list_of_num = [randint(0,50) for i in range(10)]
- print(list_of_num)
- list_of_char = random_char(50)
- print(list_of_char)
- search_for_enumerate(list_of_num, 50, False)
- search_for_enumerate(list_of_char, "a", False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement