-
Notifications
You must be signed in to change notification settings - Fork 0
/
listAPCI.py
144 lines (123 loc) · 4.15 KB
/
listAPCI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
programe goals:
3. pull the values stored at specific indexes
4. conver input to INTs
5. put all action in a while loop
6.add exit option
"""
import random
myList = []
uniqu_list = []
def mainProgram():
#build our while loop
while True:
print("Hello, there! Let's work with lists!")
print("Please choose from following options. type the number of the choise")
choise = input("""1. Add to a list,
2. Return a value in a list,
3. Add a bunch
4. Random search,
5. Liner search
6. Sort list
7. print list
8. recursive binary search
9. new Random
10.Quit """)
if choise == "1":
addTolist()
elif choise == "2":
indexValues()
elif choise == "3":
addAbunch()
elif choise == "4":
randomeSearch()
elif choise == "5":
linerSearch()
elif choise == "6":
sortList(myList)
elif choise == "7":
printLists()
elif choise == "8":
searchItem = input("What are you looking for? ")
recursiveBinarySearch(unique_list, 0, len(unique_list)-1, int(searchItem))
elif: choise == "9":
newrandom()
else:
break
def addToList():
print("Adding to a list! Great choise!")
newItem = input("Type an interger here! ")
myList.append(int(newItem))
#we need to think about errors!
def addAbunch():
print("We're gonna add a bunch of numbers to your list!")
numToAdd = input(" How many new inegers would you like to add? ")
numRange = input("And how high would you like these numbers to go? ")
for x in range(0, int(numToAdd)):
myList.append(random.randint(0,int(numRange)))
print("Your list is complete!")
def sortLists(myList):
#"myList" is the ARGUMENT this function takes.
for x in myList:
if x not in unique_list:
unque_list.append(x)
unique_list.sort()
showMe = input("Wanna see your new, sorted list? Y/N")
if showMe.lower() =="y":
print(unique_list)
def newRandom():
if len(unique_list) > 0:
wichOne = input("Wich list do you want to search? Sorted or un-sorted? ")
if whichOne.lower() == "sorted":
print(unique_list[random.randit(0, len(unique_list)-1)])
else:
print(myList[random.randit(0, len(myList)-1)])
else:
print(myList[random.randit(0, len(myList)-1)])
def randomSearch():
print("Why doyou chosie this ")
print(myList[random.randit(0, len(myList)-1)])
def linerSearch():
print("WE'er going to go through this list one item at a time!")
searchValue = input("What are you looking for? ")
for x in range(len(myList)):
if myList[x] == int(searchValue):
print("Your item is at index postion {}".format(x))
def recursiveBinarySearch(unique_list, low, high, x):
if high >= low:
mid = (high + low) // 2
if unique_list[mid] == x:
print("Your number is at index postion{}".format(mid))
return mid
elif unique_list[mid] > x:
return recursiveBinarySearch(unique_list, mid-1, x)
else:
return recursiveBinarySearch(unique_list, mid +1, high, x)
else:
print("Your number isn't here!")
def iterativeBinarySearch(unique_list, x):
low = 0
high = len(unique_list)-1
mid = 0
while low <= high:
mid = (high + low) // 2
if unique_list[mid] <x:
low = mid + 1
elif unique_list[mid] > x:
high = mid - 1
else:
return mid
return -1
def indexValues():
print("At what index position do you want to search?")
indexPos = input("Type an index postion here: ")
print(myList[int(indexPos)])
def printLists():
if len(unique_list) == 0:
print(myList)
else:
wichOne = input("Wich list do you want to see? Sorted or un-sorted? ")
if wichOne.lower() == "sorted":
print(unique_list)
if __name__== "__main__":
mainProgram()