• API
• FAQ
• Tools
• Archive
daily pastebin goal
46%
SHARE
TWEET

# Untitled

a guest Mar 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2.
3. def periodiska_systemet():
4.     list = ["H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Fl","Lv"]
5.     return list
6.
7. # Syntaxkontroll
8. import string
9.
10.
11. class Node:
12.     def __init__(self, value=None, next=None):
13.         self.value = value  # Håller ett värde för noden
14.         self.next = next    # Sätter en pekare på vilken nod som är nästa
15.
16.     def __str__(self):
17.         return self.value   # Returnerar värdet på noden
18.
19.
21.     def __init__(self):
22.         self.__first = None     # Sätter en pekare på den första noden i kön
23.         self.__last = None      # Sätter en pekare på den sista noden i kön
24.
25.     def enqueue(self, value):   # Metod för att lägga till noder i kön
26.
27.         new_node = Node(value)
28.
29.         if self.isEmpty():
30.             self.__first = new_node
31.             self.__last = new_node
32.         else:
33.             self.__last.next = new_node     # Den senaste noden pekar nu på den nya tillagda noden
34.             self.__last = new_node          # Den nya tillagda noden tilldelas den sista platsen
35.
36.     def dequeue(self):                      # Metod för att ta ut den första noden i kön
37.         value = self.__first.value
38.         self.__first = self.__first.next    # Sätter den som är efter till först i kön
39.         return value
40.
41.     def isEmpty(self):                      # Kollar om kön är tom
42.         if self.__first is None:
43.             return True
44.         else:
45.             return False
46.
47.     def peek(self):
48.         if not self.isEmpty():
49.             return self.__first.value
50.         else:
51.             return None
52.
53.
54. class Syntaxfel(Exception):
55.     pass
56.
57. def errorPrinter(q):
58.     error_str = ""
59.     while not q.isEmpty():
60.         x = q.dequeue()
61.         x=str(x)
62.         error_str += x
63.     return error_str
64.
65.
66. def LETTER(q):
67.
68.     ALPHABET = alphabetmaker(2)
69.
70.     tecken = q.dequeue()
71.
72.     if tecken in ALPHABET:
73.         print(tecken)
74.         return tecken
76.
77.
78. def letter(q):
79.
80.     alphabet = alphabetmaker(0)
81.
82.     tecken = q.dequeue()
83.
84.     if tecken in alphabet:
85.         print(tecken)
86.         return tecken
87.     raise Syntaxfel("Ska vara en stor bokstav")
88.
89.
90. def num(q):
91.
92.     number = q.dequeue()
93.
94.     next = q.peek()
95.
96.
97.
98.     if type(number) is int and number > 0:
99.
100.         if type(next) is int:
101.             print(number)
102.
103.             while type(next) is int:
104.
105.                 nextnumber = q.dequeue()
106.                 next = q.peek()
107.
108.                 print(nextnumber)
109.             return
110.
111.     if type(number) is int and number >= 2:
112.         print(number)
113.         return
114.     elif type(number) is int:
115.         raise Syntaxfel("För litet tal vid radslutet " + errorPrinter(q))
116.     else:
117.         raise Syntaxfel("String istället för int " + errorPrinter(q))
118.
119.
120. # def num(q):
121. #
122. #     number = q.dequeue()
123. #
124. #     next = q.peek()
125. #
126. #     if type(number) is int and number >= 2:
127. #         print(number)
128. #         while type(next) is int:
129. #
130. #             nextnumber = q.dequeue()
131. #             next = q.peek()
132. #
133. #             print(nextnumber)
134. #         return
135. #     if type(number) is int:
136. #         raise Syntaxfel("För litet tal vid radfel")
137. #     else:
138. #         raise Syntaxfel("String istället för int")
139. #
140.
142.
143.     alphabet = alphabetmaker(0)
144.
145.     LETTER_CAPITAL = LETTER(q)
146.
147.     next = q.peek()
148.
149.     if next in alphabet:
150.         letter_lower = letter(q)
151.         if LETTER_CAPITAL + letter_lower in periodiska_systemet():
152.             return
153.         raise Syntaxfel("Okänd atom vid radslutet " + errorPrinter(q))
154.     else:
155.         if LETTER_CAPITAL in periodiska_systemet():
156.             return
158.
159.
161.     alphabet = alphabetmaker(0)
162.     ALPHABET = alphabetmaker(2)
163.     next = q.peek()
164.
165.     if next == "(":
166.         print(next)
167.         q.dequeue()  # Tar ut "("
169.
170.         # next = q.peek()
171.
172.         # if next is ")":
173.         #     print(next)
174.         #     q.dequeue()  # Tar ut ")"
175.         #     next = q.peek()
176.         #     if type(next) is int:
177.         #         num(q)
178.         #         return
180.         # else:   #        if next is not ")":
182.
183.     if next is ")":
184.         print(next)
185.         next = q.peek()
186.         q.dequeue()
187.         if type(next) is int:
188.             num(q)
189.             return
191.
192.     if next in ALPHABET:
194.         next = q.peek()
195.         if type(next) is int:
196.             num(q)
197.             return
198.         if next is ")":
199.             raise Syntaxfel("Felaktig gruppstart vid radslutet " + errorPrinter(q))
200.
201.         # else:
202.         #     return
203.     if next is None:
204.         raise Syntaxfel("Saknad högerparentes vid radslutet")       # Då next är Nonetype, finns det fler scenarion?
205.
206.     if type(next) in alphabet: ############ fortsätt här
207.
208.
210.
212.
213.     next = q.peek()
214.
215.     ALPHABET = alphabetmaker(2)
216.
217.     alphabet = alphabetmaker(0)
218.
219.     if next == "(":
220.
221.         #print("next 1")
223.         return
224.
225.     if next in ALPHABET:
226.         #print("next 2")
228.         return
229.
230.     if next == ")":
231.         #print("next 3")
233.
234.     if next in alphabet:
235.         raise Syntaxfel("Felaktig gruppstart")
236.
239.     print("123klar\n")
240.
241.
244.     string_int=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
245.     for tecken in string:
246.         if tecken in string_int:
247.             q.enqueue(int(tecken))
248.         else:
249.             q.enqueue(tecken)
250.     return q
251.
252.
253. def alphabetmaker(x):
254.
255.     if x > 0:
256.         alph = string.ascii_uppercase
257.     else:
258.         alph = string.ascii_lowercase
259.
260.     list = []
261.     for i in alph:
262.         list.append(i)
263.     return list
264.
265.
266. def tryProgram(q):
267.     # q=makeQueueforFormel("sampleinput1")
270.
271.     try:
273.         print("Följer syntax")
274.     except Syntaxfel as fel:
275.         print(str(fel))
276.
277. def runProgram(file):
278.     with open(file, "r", encoding="utf-8") as r_file:
279.         print("Fil: ", file)
284.             print("molekyl som testas: ", rad)
285.
288.                 tryProgram(q)
290.                 print("_____________________________")
291.
292. runProgram("sampleinput2")
293.
294. # runProgram()
295. ##########################
296. # Nacl <- kolla för liten bokstav i readGroup.
297. # a
298. # (Cl)2)3
299. # )
300. 2
301. #
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top