This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| # Задание: https://ibb.co/NKprbMW | |
| number = ("42\n" | |
| "1,234\n" | |
| "6,368,745\n" | |
| "12,34,567\n" | |
| "1234") | |
| numberRegex = re.compile(r'''^\d{1,3},\d{3},\d{3}|^\d{1,3},\d{3}|^\d{1,3}$''', re.MULTILINE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Задание - https://ibb.co/54s5xwy | |
| import re | |
| names = ("Satoshi Nakamoto\n" | |
| "Alice Nakamoto\n" | |
| "RoboCop Nakamoto\n" | |
| "satoshi Nakamoto\n" | |
| "Mr. Nakamoto\n" | |
| "Nakamoto\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| phrases = ("Alice eats apples.\n" | |
| "Bob pets cats.\n" | |
| "Carol throws baseballs.\n" | |
| "Alice throws Apples.\n" | |
| "BOB EATS CATS.\n" | |
| "RoboCop eats apples.\n" | |
| "ALICE THROWS FOOTBALLS.\n" | |
| "Carol eats 7 cats.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def strong_pass(your_pass): | |
| passRegex1 = re.compile(r'''[A-Z]''') # Проверяем наличие больших букв | |
| passRegex2 = re.compile(r'''[a-z]''') # Проверяем наличие маленьких букв | |
| passRegex3 = re.compile(r'''\d''') # Проверяем наличие цифр | |
| result = passRegex1.search(your_pass) | |
| result2 = passRegex2.search(your_pass) | |
| result3 = passRegex3.search(your_pass) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Animal: | |
| name = "" | |
| category = "" | |
| def __init__(self, name): | |
| self.name = name | |
| def set_category(self, category): | |
| self.category = category |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| class Server: | |
| def __init__(self): | |
| """Creates a new server instance, with no active connections.""" | |
| self.connections = {} | |
| def add_connection(self, connection_id): | |
| """Adds a new connection to this server.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| import re | |
| def alphabet_position(text): | |
| """This function replaces every letter with its position in the | |
| alphabet.""" | |
| alphabet = (dict(enumerate(string.ascii_lowercase))) # Creating a dictionary with alphabet | |
| alphabet_updated = {value: key + 1 for key, value in alphabet.items()} # Swapping keys and values | |
| lower_text = text.lower() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def high_and_low(numbers): | |
| """In this little assignment you are given a string of space separated numbers, and have to return the highest | |
| and lowest number. """ | |
| int_numbers = [] # Creating a list for inputting integers | |
| for number in numbers.split(): # Iteration through the string with numbers | |
| int_numbers.append(int(number)) # Writing integers into a created list | |
| new_numbers = sorted(int_numbers) # Sorting numbers | |
| return str(new_numbers[-1]) + " " + str(new_numbers[0]) # Returning the result | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_sum(a, b): | |
| """Given two integers a and b, which can be positive or negative, find the sum of all the numbers between | |
| including them too and return it. If the two numbers are equal return a or b. """ | |
| if a > b: # Range function won't work if a > b, so we replacing them by each other | |
| new_a = b | |
| new_b = a | |
| return sum(list(range(new_a, new_b + 1))) # Returning a sum number of all numbers in range from a to b | |
| elif a == b: | |
| return a | b # Returning of a or b, if numbers are equal | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def iq_test(numbers): | |
| """Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given | |
| numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help | |
| Bob — to check his answers, he needs a program that among the given numbers finds one that is different in | |
| evenness, and return a position of this number. """ | |
| all_numbers: list = [] # Creating a list to save all odd and even values | |
| odd_count: int = 0 # Creating an int to count an odd value | |
| even_count: int = 0 # Creating an int to count an even value |