Zadania B

This commit is contained in:
s464968 2022-11-05 19:53:13 +01:00
commit 08d7ce3999
8 changed files with 1193 additions and 0 deletions

29
B/B01.py Normal file
View File

@ -0,0 +1,29 @@
import regex as re
def is_name_correct(name: str) -> bool:
result = re.match(r'^(\p{Lu}|\p{Lt}).+$', name)
return True if result else False
def is_phone_correct(name: str) -> bool:
result = re.match(r'^\(\d{2}\)\s*\d{3}-\d{2}-\d{2}', name)
return True if result else False
def is_zipcode_correct(name: str) -> bool:
result = re.match(r'^\d{2}-\d{3}$', name)
return True if result else False
first_name = input("Poda imie: ")
second_name = input("Poda nazwisko: ")
city = input("Poda nazwe miasta: ")
phone_number = input("Poda numer telefonu: ")
zip_code = input("Poda kod pocztowy: ")
print("Imie poprawne!") if is_name_correct(first_name) else print("Imie niepoprawne!")
print("Nazwisko poprawne!") if is_name_correct(second_name) else print("Nazwisko niepoprawne!")
print("Miasto poprawne!") if is_name_correct(city) else print("Miasto niepoprawne!")
print("Telefon poprawny!") if is_phone_correct(phone_number) else print("Telefon niepoprawny!")
print("Kod pocztowy poprawny!") if is_zipcode_correct(zip_code) else print("Kod pocztowy niepoprawny!")

22
B/BO2.py Normal file
View File

@ -0,0 +1,22 @@
import regex as re
def is_line_correct(line: str) -> bool:
result = re.match(r'^.+;\d+;\d+$', line)
return True if result else False
def is_correct_csv(file_name: str) -> bool:
file = open(file_name, 'r')
is_correct = True
for line in file:
is_correct = is_correct and is_line_correct(line)
if not is_correct:
break
file.close()
return is_correct
if __name__ == '__main__':
file_n = input('Podaj nazwe pliku csv: ')
print('Plik CSV jest poprawny!') if is_correct_csv(file_n) else print('Plik CSV jest niepoprawny!')

11
B/BO3.py Normal file
View File

@ -0,0 +1,11 @@
import regex as re
def replace_vulgarism(usr_input: str) -> str:
return re.sub(r'\p{Ll}*(chuj|pizd|jeb|pierd|kur)\p{Ll}*', '---', usr_input, flags=re.IGNORECASE)
if __name__ == '__main__':
usr_input = input("Podaj przykładowe zdanie: ")
print("Zdanie zmienione: ")
print(replace_vulgarism(usr_input))

22
B/BO4.py Normal file
View File

@ -0,0 +1,22 @@
import regex as re
def get_email_addresses(usr_input: str) -> list:
return re.findall(r"^[A-Za-z0-9!#$%&'*+=?^_`{|}~.\-\/]{1,64}@[a-zA-Z0-9.\-]+$", usr_input)
def return_email_addresses_in_file(file_name: str) -> list:
f = open(file_name, "r")
email_addresses = []
for line in f:
email_addresses_from_line = get_email_addresses(line)
if email_addresses_from_line:
email_addresses.append(email_addresses_from_line)
f.close()
return email_addresses
if __name__ == '__main__':
usr_input = input("Podaj nazwe pliku: ")
for email in return_email_addresses_in_file(usr_input):
print(email)

1000
B/MOCK_DATA.csv Normal file

File diff suppressed because it is too large Load Diff

31
B/emails.txt Normal file
View File

@ -0,0 +1,31 @@
simple@example.com
very.common@example.com
disposable.style.email.with+symbol@example.com
other.email-with-hyphen@example.com
fully-qualified-domain@example.com
user.name+tag+sorting@example.com
x@example.com
example-indeed@strange-example.com
test/test@test.com
admin@mailserver1
example@s.example
" "@example.org
"john..doe"@example.org
mailhost!username@example.org
"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
user%example.com@example.org
user-@example.org
postmaster@[123.123.123.123]
postmaster@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]
Abc.example.com
A@b@c@example.com
a"b(c)d,e:f;g<h>i[j\k]l@example.com
just"not"right@example.com
this is"not\allowed@example.com
this\ still\"not\\allowed@example.com
1234567890123456789012345678901234567890123456789012345678901234+x@example.com
i_like_underscore@but_its_not_allowed_in_this_part.example.com
QA[icon]CHOCOLATE[icon]@test.com

28
B/test_B01.py Normal file
View File

@ -0,0 +1,28 @@
import unittest
import B01
class TestNames(unittest.TestCase):
def test_correct(self):
self.assertEqual(B01.is_name_correct("Nowy York"), True) # add assertion here
def test_wrong(self):
self.assertEqual(B01.is_name_correct("0123"), False)
class TestPhoneNumbers(unittest.TestCase):
def test_correct(self):
self.assertEqual(B01.is_phone_correct("(61) 222-45-56"), True)
def test_wrong(self):
self.assertEqual(B01.is_phone_correct("124466780"), False)
class TestZipCode(unittest.TestCase):
def test_correct(self):
self.assertEqual(B01.is_zipcode_correct("11-111"), True)
def test_wrong(self):
self.assertEqual(B01.is_zipcode_correct("(61) 222-45-56"), False)
if __name__ == '__main__':
unittest.main()

50
B/test_BO3.py Normal file
View File

@ -0,0 +1,50 @@
import unittest
import BO3
class TestVulgarism(unittest.TestCase):
def test_1(self):
usr_input = 'W ogóle przystojny, zajebisty, kurwa, koleś'
correct = 'W ogóle przystojny, ---, ---, koleś'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_2(self):
usr_input = 'Jebnąć cię czy się zamkniesz już?'
correct = '--- cię czy się zamkniesz już?'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_3(self):
usr_input = 'Jebać to mało, zajebać trzeba!'
correct = '--- to mało, --- trzeba!'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_4(self):
usr_input = 'Wyjebał się chuj'
correct = '--- się ---'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_5(self):
usr_input = 'Stara kurwa napierdala w telefon, a ja tu browarka sączę'
correct = 'Stara --- --- w telefon, a ja tu browarka sączę'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_6(self):
usr_input = 'Kurwa, jak to, kurwa, usłyszałem, to mnie, kurwa, z zawiasów wypierdoliło'
correct = '---, jak to, ---, usłyszałem, to mnie, ---, z zawiasów ---'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_7(self):
usr_input = 'Ale mówię ci, zajebiście było'
correct = 'Ale mówię ci, --- było'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_8(self):
usr_input = 'A ja się, kurwa, czuję właśnie jak w Dniu świra'
correct = 'A ja się, ---, czuję właśnie jak w Dniu świra'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_9(self):
usr_input = 'Mój wujek ma, kurwa, no ten, kurwa...'
correct = 'Mój wujek ma, ---, no ten, ---...'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
def test_10(self):
usr_input = 'Kurwa, choć nie na temat to dodam, że...'
correct = '---, choć nie na temat to dodam, że...'
self.assertEqual(BO3.replace_vulgarism(usr_input), correct) # add assertion here
if __name__ == '__main__':
unittest.main()