Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Codes/license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'''
Duara Internship Code Challenge

Task 1

This program stores and queries a list of license plate number
'''
import random
import re

letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
numbers = '0123456789'


#stores the number plates to a file
def store():
with open('license.txt', 'w') as file:
for x in range(0, 200000):
license = random.choice(letters) + random.choice(
letters) + random.choice(letters) + '-' + random.choice(
numbers) + random.choice(numbers) + random.choice(numbers)
file.write(license + '\n')

query()


def query():
lst = [] # the list will store license plates that begin with PLB
regex1 = 'PLB-123' # regex pattern to search if a PLB-123 is a member of a set
regex2 = '^(PLB)' # regex pattern to search plates that begin with PLB
file = open('license.txt', 'r')
for plates in file:
plates = plates.strip()
if re.match(regex1, plates):
print 'license plate PLB-123 a member of the set'
if re.match(regex2, plates):
lst.append(plates)
print 'Number of license plates that begin with PLB: ' + str(len(lst))
if len(lst) > 0:
print 'List of license plates that begin with PLB:'
for x in lst:
print x


store()
20 changes: 20 additions & 0 deletions Codes/recursive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''
Duara Internship Code Challenge

Task 2

Write a function that divides two numbers and returns their quotient.
Use recursive subtraction to find the quotient.
The function should only take two arguments.
'''


def quotient(numerator, denominator):
if 0 <= numerator < denominator:
return 0
if numerator >= denominator:
return quotient(numerator - denominator, denominator) + 1
if numerator < 0:
return quotient(numerator + denominator, denominator) - 1

print quotient(23.6,5.6)
28 changes: 28 additions & 0 deletions Codes/t9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''
Duara Internship Code Challenge - 22nd May 2018

Task 4

Converting a list of t9 characters and returning a list of all words in dictionary represented in a dictionary
'''
import re

keypad = ['', '', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']


def convert(number):
possible_words = []
number_str = str(number)
pattern = "^"
for x in number_str:
pattern = pattern + "[" + keypad[int(x)] + "]"
pattern += "$" #regex pattern to search the words that match the pattern in the dictionary provided with valid words
file = open('words.txt', 'r')
for word in file:
if re.match(pattern, word.lower()):
possible_words.append(word.strip())

print possible_words


convert('228')
Loading