-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskl.py
More file actions
178 lines (152 loc) · 3.32 KB
/
skl.py
File metadata and controls
178 lines (152 loc) · 3.32 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Implements the ADT Stack
class Stack:
def __init__(self):
self.__items = []
def push(self, item):
self.__items.append(item)
def pop(self):
return self.__items.pop()
def isEmpty(self):
if self.__items == []:
return True
else:
return False
def __len__(self):
return len(self.__items)
# Implements the ADT Queue
class Queue:
def __init__(self):
self.__items = []
def enqueue(self, item):
self.__items.insert(0, item)
def dequeue(self):
return self.__items.pop()
def size(self):
return len(self.__items)
def isEmpty(self):
if self.__items == []:
return True
else:
return False
def menu():
choice = 1
while choice != 0:
print "\nStart which function?"
print "1: Uppgift 2 - Stack"
print "2: Uppgift 3 - Queue"
print "3: Uppgift 4 - parcheck"
print "4: Uppgift 5 - parcheck v 2.0"
print "5: Uppgift 6 - tagcheck"
print "6: Uppgift 7 - Pictionary"
choice = input("Ditt val: ")
if choice == 0:
break
elif choice == 1:
uppg2()
elif choice == 2:
uppg3()
elif choice == 3:
symbolString = raw_input("Skriv ett antal parenteser: ")
parChecker(symbolString)
elif choice == 4:
symbolString = raw_input("Skriv en string med parenteser: ")
parChecker2(symbolString)
elif choice == 5:
tagString = raw_input("Skriv ett antal startande och avslutande 'p'-taggar: ")
tagChecker(tagString)
elif choice == 6:
mailList()
# Functions that do the specified exercises
def uppg2():
print "\n"
stack = Stack()
print stack.isEmpty()
elements = [7, 6, 100, "Y"]
for each in elements:
stack.push(each)
print stack.pop()
print stack.isEmpty()
stack.push(9)
iterations = 0
while iterations < 4:
print stack.pop()
iterations += 1
def uppg3():
print "\n"
queue = Queue()
print queue.isEmpty()
print queue.size()
queue.enqueue("first in")
print queue.size()
queue.enqueue("second in")
print queue.dequeue()
print queue.isEmpty()
def parChecker (symbolString):
print "\n"
s = Stack()
balanced = True
for symbol in symbolString:
if symbol == "(":
s.push(symbol)
else:
if s.isEmpty() == True:
balanced = False
break
else:
s.pop()
if s.isEmpty() == True and balanced == True:
print "True"
else:
print "False"
def parChecker2(symbolString):
print "\n"
s = Stack()
balanced = True
for symbol in symbolString:
if symbol == "(":
s.push(symbol)
elif symbol == ")":
if s.isEmpty() == True:
balanced = False
break
else:
s.pop()
else:
pass
if s.isEmpty() == True and balanced == True:
print "True"
else:
print "False"
def tagChecker(tagString):
stack_p = Stack()
stack_slash = Stack()
for symbol in tagString:
if symbol == "<" or symbol == ">":
pass
elif symbol == "/":
stack_slash.push(symbol)
else:
stack_p.push(symbol)
outcome = float(len(stack_p)) / float(len(stack_slash))
if outcome == 1 or outcome == 2:
print True
else:
print False
def mailList():
mail_list = {'Anders': 'nan@nan.com', 'Ola': 'non@bill.com'}
choice = 1
while choice != 0:
print "What to do?"
print "1: Add till person"
print "2: Visa lista"
print "0: Backa"
choice = input("Deine vales: ")
if choice == 0:
pass
elif choice == 1:
name = raw_input("Namn personen? ")
mail = raw_input("Mailadresssszs? ")
mail_list[name]=mail
elif choice == 2:
print mail_list
menu()