How to use getcharcount method in pyatom

Best Python code snippet using pyatom_python

compiler.py

Source:compiler.py Github

copy

Full Screen

1import os23hatalar = {4 "ikiNoktalar": [],5 "trueFalseler": [],6 "tablar": [],7 "parantezler": [],8}91011def isExists(ertype):12 if len(hatalar[ertype]) > 0:13 return "Var" 14 else:15 return "Yok"1617def getStringOfLines(which):18 stringim = ""19 for i, x in enumerate(hatalar[which]):20 if not i == 0:21 stringim = stringim + ',' + str(x) 22 else: 23 stringim += str(x) 24 if not stringim == '':25 return stringim26 else: 27 return 'Yok'2829def getLine(line):30 file = open(targetFileName, 'r')31 for i, l in enumerate(file):32 if l == line:33 return (i+1)3435def findPreviousLine(line):36 file = open(targetFileName, 'r')37 prefile = file.readlines()[getLine(line) - 2]38 return prefile3940def findAfterLine(line):41 file = open(targetFileName, 'r')42 try:43 afline = file.readlines()[getLine(line)] 44 return afline45 except:46 pass47484950def getCharCount(line):51 i = 052 for x in line:53 if line != ' ':54 if x == ' ':55 i+=156 else: 57 break58 # i = boşluk sayısı59 return i606162def getParentStatement(line):63 file = open(targetFileName, 'r')64 look = False65 for x in file.readlines().reverse():66 if x == line:67 look = True68 pass 69 if look == True:70 if (x.replace(" ", "")).startswith('if') == True:71 return x 72def tabErr(line):73 preline = findPreviousLine(line)74 afterline = findAfterLine(line) or ""75 if (line.replace(" ", "")).startswith('if') == True:76 if not getLine(line) in hatalar["tablar"]:77 if getCharCount(line) != getCharCount(preline):78 hatalar["tablar"].append(getLine(line))79 if (preline.replace(" ", "")).startswith('if') == True:80 if not getLine(line) in hatalar["tablar"]:81 if (getCharCount(afterline) or 0) != getCharCount(line):82 hatalar["tablar"].append(getLine(line))83 if not getCharCount(line) >= 1:84 hatalar["tablar"].append(getLine(line))85 86 elif (getCharCount(afterline) != getCharCount(line)) or (getCharCount(afterline) != getCharCount(preline)) or (getCharCount(preline) != getCharCount(line)):87 if not getLine(line) in hatalar["tablar"]:88 hatalar["tablar"].append(getLine(line))89 9091def ikiNokta(line):92 if (line.replace(' ', '')).startswith('if') == True:93 if line.endswith(':') != True:94 hatalar["ikiNoktalar"].append(getLine(line))9596def parantheseHatasi(line):97 if line.count('(') != line.count(')'):98 hatalar["parantezler"].append(getLine(line))99100def trueFalse(line):101 if ("true" or "false") in line:102 hatalar["trueFalseler"].append(getLine(line))103def compileFile():104 file = open(targetFileName, 'r')105 for number, line in enumerate(file.readlines()):106 ikiNokta(line)107 trueFalse(line)108 tabErr(line)109 parantheseHatasi(line)110 print('İki nokta hatası :' + isExists('ikiNoktalar') + '(Satırlar:' + getStringOfLines("ikiNoktalar") + ')')111 print('True & False Hatası :' + isExists('trueFalseler') + '(Satırlar:' + getStringOfLines("trueFalseler") + ')')112 print('Tab Hatası :' + isExists('tablar') + '(Satırlar:' + getStringOfLines("tablar") + ')')113 print('Parantez Hatası :' + isExists('parantezler') + '(Satırlar:' + getStringOfLines("parantezler") + ')')114115fileName = input('Dosya adını uzantısı olmadan giriniz. (Aynı dizinde bulunmalıdır.) : ')116targetFileName = fileName + ".py"117isFound = False118for file in os.listdir(os.getcwd()):119 if file == targetFileName and file != 'compiler.py':120 isFound = True 121 compileFile() ...

Full Screen

Full Screen

challenge_17.py

Source:challenge_17.py Github

copy

Full Screen

1#Oliver Hamilton2#Challenge 17 - Number letter counts3#27/12/202045#CONSTANTS67#Mapping from numbers less than 20 to character counts8unitsMapping = {'1': 'one',9 '2': 'two',10 '3': 'three',11 '4': 'four',12 '5': 'five',13 '6': 'six',14 '7': 'seven',15 '8': 'eight',16 '9': 'nine',17 '10': 'ten',18 '11': 'eleven',19 '12': 'twelve',20 '13': 'thirteen',21 '14': 'fourteen',22 '15': 'fifteen',23 '16': 'sixteen',24 '17': 'seventeen',25 '18': 'eighteen',26 '19': 'nineteen'27 }28#Mapping from tens (20, 30, 40, ...) to character counts29tensMapping = {'2': 'twenty',30 '3': 'thirty',31 '4': 'forty',32 '5': 'fifty',33 '6': 'sixty',34 '7': 'seventy',35 '8': 'eighty',36 '9': 'ninety'37 }3839def getCharCount(num):40 global unitsMapping41 global tensMapping4243 if int(num) == 0:44 return ""4546 #For thousands47 if len(num) >= 4:48 thousandsDigit = num[0]49 hundredsDigit = num[1]50 tensDigit = num[2]51 unitsDigit = num[3]5253 #If the hundreds are non-zero, the 'and' doesn't need to be included54 if hundredsDigit != '0':55 return getCharCount(thousandsDigit) + 'thousand' + getCharCount(hundredsDigit + tensDigit + unitsDigit)5657 #If one of the units and tens digits are non-zero, the 'and' must be included58 elif tensDigit != '0' or unitsDigit != '0':59 return getCharCount(thousandsDigit) + 'thousand' + 'and' + getCharCount(tensDigit + unitsDigit)6061 #If the hundreds, tens, and units are all zero, the 'and' doesn't need to be included to be included62 else:63 return getCharCount(thousandsDigit) + 'thousand'6465 #For hundreds66 elif len(num) >= 3:67 hundredsDigit = num[0]68 tensDigit = num[1]69 unitsDigit = num[2]7071 #If both tens digit and units digit are 0, don't include the 'and'72 if tensDigit == '0' and unitsDigit == '0':73 return getCharCount(hundredsDigit) + 'hundred'7475 else:76 return getCharCount(hundredsDigit) + 'hundred' + 'and' + getCharCount(tensDigit + unitsDigit)7778 #For tens79 elif int(num) >= 20:80 tensDigit = num[0]81 unitsDigit = num[1]8283 return tensMapping[tensDigit] + getCharCount(unitsDigit)8485 #For units / teens 86 elif int(num) < 20:8788 #If the tens digit is 0, return only the value of the units digit89 if num[0] == '0':90 return unitsMapping[num[1]]9192 else:93 return unitsMapping[num]94959697#Number of letters used in sequence of numbers98letterCount = 099100#Iterate over integers from 1 to 1000 (inclusive)101for i in range(1, 1001):102 #Convert number to string103 currentNum = str(i)104 print(getCharCount(currentNum))105 letterCount += len(getCharCount(currentNum))106107print(letterCount) ...

Full Screen

Full Screen

LessonCreator.py

Source:LessonCreator.py Github

copy

Full Screen

1from book import Lesson2import logging3class LessonCreator:4 """Creates lessons out of book chapters"""5 def __init__(self, bookName, minChars):6 self._bookName = bookName7 self._minChars = minChars8 def createLessons(self, chapters):9 logging.debug('createLessons()')10 self._lessons = list()11 for chapter in chapters:12 self._parseChapter(chapter)13 return self._lessons14 def _parseChapter(self, chapter):15 logging.debug('Parse chapter ' + chapter.getName())16 lessons = list()17 lesson = Lesson.Lesson(self._bookName, chapter.getName(), 1)18 logging.debug('New Lesson: ' + lesson.getName())19 for paragraph in chapter.getParagraphs():20 lesson.addParagraph(paragraph)21 logging.debug('Add paragraph with ' + str(paragraph.getCharCount()) + ' chars.')22 # End lesson - long enough23 if lesson.getCharCount() >= self._minChars:24 logging.debug('Lesson long enough (' + str(lesson.getCharCount()) + ' chars)')25 lessons.append(lesson)26 lesson = Lesson.Lesson(self._bookName, chapter.getName(), len(lessons) + 1)27 logging.debug('New Lesson: ' + lesson.getName())28 logging.debug('Done with chapter')29 # Merge last lesson (if too short)30 if lesson.getCharCount() > 0:31 if lesson.getCharCount() < self._minChars and len(lessons) > 0:32 logging.debug('Last lesson too short (' + str(lesson.getCharCount()) + ') merging with last lesson')33 prevLesson = lessons[-1]34 if prevLesson:35 prevLesson.mergeLesson(lesson)36 logging.debug('Previous lesson now contains ' + str(prevLesson.getCharCount()) + ' chars')37 else:38 logging.debug('No previous lesson exists, creating lesson anyway')39 lessons.append(lesson)40 else:41 lessons.append(lesson)42 # Add all lessons to lesson list...

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