How to use _setString method in pyatom

Best Python code snippet using pyatom_python

flip.py

Source:flip.py Github

copy

Full Screen

1from random import randint2class Tile(object):3 def __init__(self,ID):4 self.up = False5 self.ID = ID6 self.contents = ' '7 self._string = ' ' + ID + ' '8 # self._string[i] notes9 # 0 = note: 010 # 1 = decorative if flipped11 # 2 = note: 112 # 3 = decorative if flipped13 # 4 = content14 # 5 = decorative if flipped15 # 6 = note: 216 # 7 = decorative if flipped17 # 8 = note: 318 def __str__(self):19 return self._string20 def _setstring(self,I,V):21 """T._setstring([index],[value])22 Sets self._string's index to that value."""23 if I not in range(9):24 raise IndexError("Index must be [0:9]")25 elif type(V) != str:26 raise TypeError("Value must be in string format")27 elif len(V) != 1:28 raise TypeError("Value must be precisely one char")29 else:30 self._string = self._string[:I] + str(V) + self._string[(I+1):]31 32 def note(self,n):33 """T.note([0,1,2,3])34 Writes a note for the argument on the tile."""35 if self.up:36 pass37 elif n == '0':38 if self._string[0] == '0':39 self._setstring(0,' ')40 else:41 self._setstring(0,'0')42 elif n == '1':43 if self._string[2] == '1':44 self._setstring(2,' ')45 else:46 self._setstring(2,'1')47 elif n == '2':48 if self._string[6] == '2':49 self._setstring(6,' ')50 else:51 self._setstring(6,'2')52 elif n == '3':53 if self._string[8] == '3':54 self._setstring(8,' ')55 else:56 self._setstring(8,'3')57 else:58 ERR = "Tile object's note() requires 0,1,2,3 as input"59 ERR += ", not " + str(n) + " of type " + str(type(n))60 raise TypeError(ERR)61 def flip(self,ready=True):62 if not ready:63 self.__init__(self.ID)64 elif self.up == None:65 pass66 elif self.up:67 self._string = ' ' + self.ID + ' '68 self.up = False69 else:70 self._string = '`````````'71 self._setstring(4,self.contents)72 self.up = True73 74class Data(object):75 """Collects the values in each row and col, along with76 how many zeroes."""77 def __init__(self):78 self.row = [[0,0] for i in xrange(5)]79 self.col = [[0,0] for i in xrange(5)]80 def reset(self):81 self.__init__()82 def collect_data(self,tiles):83 self.__init__()84 for t in xrange(len(tiles)):85 self.row[t/5][1] += int(tiles[t].contents)86 self.col[t%5][1] += int(tiles[t].contents)87 if tiles[t].contents == '0':88 self.row[t/5][0] += 189 self.col[t%5][0] += 190 91class Board(object):92 def __init__(self):93 self.T = [Tile(letter) for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXY']94 self.maxscore = self.score = 195 self.data = Data()96 def __str__(self):97 border = '+ --- + --- + --- + --- + --- +'98 mini_border = '+ --- +'99 #100 ##101 ### Crafts the board102 # The Scoreboard103 output = 'Score: ' + str(self.score) + '\n'104 105 # For each row of tiles106 for Z in xrange(5):107 output += border + ' ' + mini_border + '\n'108 # For each inner line109 for i in [0,3,6]:110 111 # For each tile112 for t in xrange((Z*5),(Z*5)+5):113 output += '| ' + str(self.T[t])[i:i+3] + ' '114 # /end tile115 # prints side data116 if i == 0:117 output += '| |S: '118 if (self.data.row[Z][1])/10 < 1: output += ' '119 output += str(self.data.row[Z][1]) + '|\n'120 elif i == 3: output += '| | ~~~ |\n'121 elif i == 6:122 output += '| |0: '123 output += str(self.data.row[Z][0]) + '|\n'124 # /end line125 126 # /end row127 output += border + ' ' + mini_border128 # prints bottom data129 output += '\n' + border + '\n'130 131 # sums132 for c in xrange(5):133 output += '|S: '134 if (self.data.col[c][1])/10 < 1: output += ' '135 output += str(self.data.col[c][1])136 output += '|\n' + ('| ~~~ ' * 5) + '|\n'137 138 # zeroes139 for c in xrange(5):140 output += '|0: ' + str(self.data.col[c][0])141 output += '|\n'142 output += border143 144 #145 return output146 def reset(self):147 self.maxscore = self.score = 1148 self.data.reset()149 for tile in self.T:150 tile.flip(False)151 152 def start_game(self):153 self.reset()154 for tile in self.T:155 point = randint(0,3)156 if point != 0:157 self.maxscore *= point158 tile.contents = str(point)159 160 self.data.collect_data(self.T)161 print self162 def flip(self,n):163 self.T[n].flip()164 self.score *= int(self.T[n].contents)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from typing import List2class Recognized: 3 def __init__(self, value, string):4 self.value = value5 self.string = string6 self.length = len(string)7 self._setString = set(string)8 9 def inCommon(self, string):10 return len(self._setString.intersection(set(string)))11 12 def isIdentical(self, string):13 newSet = set(string)14 return self._setString.issubset(newSet) and self._setString.issuperset(newSet)15 16 def isSubset(self, string):17 return self._setString.issubset(set(string))18 def isSuperset(self, string):19 return self._setString.issuperset(set(string))20 def __repr__(self):21 return f"R({self.value}, {self.string})"22def groupBy(lst): 23 count = {}24 for element in lst:25 if element not in count:26 count[element] = 027 count[element] += 128 return count29def readData(sample = False) -> List[str]:30 filename = "./sample.txt" if sample else "./data.txt"31 f = open(filename, "r")32 lines = list(map(lambda x: (x.split(' | ')[0].split(), x.split(' | ')[1].split()), f.readlines()))33 f.close()34 return lines35def read1478InOutput(lines):36 nbInst = 037 for line in lines:38 for digit in line[1]:39 if len(digit) in [2, 3, 4 ,7]:40 nbInst += 141 return nbInst42def buildRecognizedList(lst):43 copyList = list(lst)44 recognized = {}45 for number in copyList:46 if (len(number) == 2):47 recognized[1] = Recognized(1, number)48 elif (len(number) == 4):49 recognized[4] = Recognized(4, number)50 elif (len(number) == 3):51 recognized[7] = Recognized(7, number)52 elif (len(number) == 7):53 recognized[8] = Recognized(8, number)54 55 for number in copyList:56 # Build 2, 3 and 5 from 1 4 7 857 if len(number) == 5:58 if (recognized[4].inCommon(number) == 3 and recognized[1].inCommon(number) == 1):59 recognized[5] = Recognized(5, number)60 elif (recognized[4].inCommon(number) == 2 and recognized[1].inCommon(number) == 1):61 recognized[2] = Recognized(2, number)62 elif (recognized[4].inCommon(number) == 3 and recognized[1].isSubset(number)):63 recognized[3] = Recognized(3, number)64 for number in copyList:65 # Build 0, 6, 9 from 1 2 3 4 5 7 866 if len(number) == 6 :67 if (recognized[5].isSubset(number) and recognized[1].isSubset(number)):68 recognized[9] = Recognized(9, number)69 elif (recognized[5].isSubset(number) and recognized[1].inCommon(number) == 1):70 recognized[6] = Recognized(6, number)71 elif (recognized[2].inCommon(number) == 4 and recognized[1].isSubset(number)):72 recognized[0] = Recognized(0, number)73 return list(recognized.values()) 74def getNumberFromRecognize(number, recognize):75 for recon in recognize:76 if (recon.isIdentical(number)):77 return recon.value78 79def getResult(lines):80 res = 081 for line in lines:82 curNum = 083 recognize = buildRecognizedList(line[0]) 84 for output in line[1]:85 curNum = curNum * 10 + getNumberFromRecognize(output, recognize)86 res += curNum87 return res88print(read1478InOutput(readData(True)))89print(read1478InOutput(readData()))90print(getResult(readData(True)))...

Full Screen

Full Screen

adders.py

Source:adders.py Github

copy

Full Screen

...45#Added creation functions6def addPerson(session):7 demoDetails = _parseUserInput("Enter basic demographic details in the following format: \n firstName(String) lastName(String) genderFemale(Boolean) birthDate(Datetime):", 4)8 demoDetails[0] = _setString(demoDetails[0])9 demoDetails[1] = _setString(demoDetails[1])10 demoDetails[2] = _setString(demoDetails[2])11 demoDetails[3] = _reIssueDateFn(demoDetails[3])1213 person = Person(firstName=demoDetails[0],14 lastName=demoDetails[1],15 genderFemale=bool(strtobool(str(demoDetails[2]))),16 birthDate=demoDetails[3])17 session.add(person)18 session.commit()19 return person20212223def addCustomer(session):24 person = addPerson(session)25 customer = Customer(person=person)26 session.add(customer)27 session.commit()28293031def addEmployee(session):32 person = addPerson(session)33 employeeDetails = _parseUserInput("Enter basic employee details in teh following format: \n role seniority location salary", 4)34 employeeDetails[0] = _setString(employeeDetails[0])35 employeeDetails[1] = _setString(employeeDetails[1])36 employeeDetails[2] = _setString(employeeDetails[2])37 employeeDetails[3] = _setString(employeeDetails[3])3839 employee = Employee(role=employeeDetails[0],40 seniority=employeeDetails[1],41 location=employeeDetails[2],42 salary=employeeDetails[3],43 person=person)44 session.add(employee)45 session.commit()46474849def addChecking(session):50 checkingDetails = _parseUserInput("Enter basic checking account details in teh following format: \n memberID(Integer) interestRate(Float) monhtlyFee(Float) balance(Float) attachedDebitCard(Boolean) Savings(Boolean)", 6)51 member = session.query(Customer).filter_by(memberID=int(checkingDetails[0])).first() ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful