Skip to content

Commit 21bccfb

Browse files
committed
new projects
1 parent 0b474e4 commit 21bccfb

4 files changed

+78
-6
lines changed

OtherSources/Task4.TxtFilesDuplicateNumbersFinder.py OtherSources/Task4_TxtFiles_Duplicate_Numbers_Finder_old.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#Initialization of variables
1+
# Initialization of variables
22
file1 = open('task_4.txt', 'r')
33
spisok = []
44
k = 0
55
p = 0
66
amount = 0
77

8-
#Input in list numbers from .txt file
8+
# Input in list numbers from .txt file
99
for i in file1:
1010
spisok.append(i[:-1])
1111
k+=1
@@ -16,7 +16,7 @@
1616
print("Загальна кількість елементів: ", k)
1717
#print(spisok)
1818

19-
#Looping through the numbers in list to find same one's
19+
# Looping through numbers in the list to find same one's
2020
while p < k:
2121
for t in range (0, k):
2222
if int(new_spisok[p]) == int(new_spisok[t]) and p!=t:
@@ -29,7 +29,7 @@
2929

3030
file2 = open('task_4_result.txt', 'w')
3131

32-
#Output loop in order (bubble)
32+
# Ordering output loop (bubble method)
3333
for i in range(0, k):
3434
for j in range(0, k-1):
3535
if len(new_spisok[j]) == len(new_spisok[j+1]):
@@ -38,12 +38,13 @@
3838
elif len(new_spisok[j]) > len(new_spisok[j+1]):
3939
new_spisok[j], new_spisok[j + 1] = new_spisok[j + 1], new_spisok[j]
4040

41-
#Saving data to file2
41+
# Saving data to file2
4242
for i in range(0, k):
4343
file2.writelines(new_spisok[i])
4444
file2.writelines('\n')
4545

4646
file2.close()
47-
#Output the result
47+
48+
# Output the result
4849
print("Кількість елементів, що повторюються: ", amount)
4950
#print(new_spisok)

OtherSources/password_generator.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from random import randint
2+
3+
# We can use password length and restricted symbols as arguments is this function
4+
def generate_password(length = 12, restricted_symbols = ""):
5+
# Creating variables for symbols (that'll be used in password) and password strings
6+
symbols = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.';\"[]}{|\\?,!#$%^&*@)(-+="
7+
password = ""
8+
9+
# Looping through restricted_symbols to delete such from a symbols string
10+
for el in restricted_symbols:
11+
try:
12+
symbols = symbols[:symbols.find(el)] + symbols[symbols.find(el)+1:]
13+
except IndexError:
14+
# That means duplicates in restricted symbols variable
15+
pass
16+
17+
# Looping length of password times to fill the password string
18+
for i in range(0, length):
19+
password = password + symbols[randint(0, len(symbols))]
20+
21+
# Returning password string
22+
return password
23+
24+
# Some tests:
25+
if __name__ == "__main__":
26+
print(generate_password())
27+
print(generate_password(20))
28+
print(generate_password(0))
29+
print(generate_password(10, "abcABCefgEFGhigHIG"))
30+
print(generate_password(10, "AAAAAaaavvv"))
31+
print(generate_password(10, ",./?|\\';\""))
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Look on phone number and validate it
2+
# Format: dddd-dddd-dddd
3+
4+
# w/o RegEx
5+
def check_phone(number):
6+
if len(number) != 14:
7+
return False
8+
9+
for i in range(0, 4):
10+
if not number[i].isdecimal() or not number[i+5].isdecimal() or not number[i+10].isdecimal():
11+
return False
12+
13+
return True if number[4] == number[9] and number[9] == "-" else False
14+
15+
# with RegEx
16+
def check_phone_regex(number):
17+
from re import findall
18+
return True if findall("\d{4}-\d{4}-\d{4}", number) else False
19+
20+
# Some tests:
21+
22+
def test_check_phone_regex():
23+
print("\n")
24+
print("Test check phone number with regex: ")
25+
print(check_phone_regex("9999-2222-1111"))
26+
print(check_phone_regex("9999-2222-111"))
27+
print(check_phone_regex("9999-2222-11s1"))
28+
print(check_phone_regex("9999-222201111"))
29+
30+
def test_check_phone():
31+
print("\n")
32+
print("Test check phone number no libs: ")
33+
print(check_phone("9999-2222-1111"))
34+
print(check_phone("9999-2222-111"))
35+
print(check_phone("9999-2222-11s1"))
36+
print(check_phone("9999-222201111"))
37+
38+
if __name__ == "__main__":
39+
test_check_phone()
40+
test_check_phone_regex()

0 commit comments

Comments
 (0)