TelenkovDmitry 5 сар өмнө
parent
commit
197064a218

+ 0 - 35
courses/class.py

@@ -1,35 +0,0 @@
-
-class Base():
-
-    BASE_STRING = "Это базовый класс"
-
-    def __init__(self) -> None:
-        pass
-
-    def print_info(self):
-        print("Это метод базового класса: ", self.BASE_STRING)
-
-
-class UpBase(Base):
-
-    BASE_STRING = "Это класс наследник"
-
-    def __init__(self) -> None:
-        pass
-
-
-# up_base = UpBase()
-# up_base.print_info()
-
-def main():
-    try:
-        5/0
-    except Exception as e:
-        print("Error!", e)
-    finally:
-        print('finaly')
-
-
-
-if __name__ == '__main__':
-    main()

+ 0 - 7
courses/python_for_begginers/project.py

@@ -1,7 +0,0 @@
-from random import *
-
-print(random())
-print(uniform(1.0, 10.0))
-num = randint(1, 118)
-print(num)
-# print(randrange(1.0, 10.0))

+ 0 - 46
courses/python_for_begginers/pytwo.py

@@ -1,46 +0,0 @@
-
-class MyClass(object):
-	
-	def __init__(self):
-		self.string = "test string"
-
-	@staticmethod
-	def print_string():
-		print "hi"
-
-
-def foo():
-	return new_my_class()
-
-
-def fooo(*args, **kwargs):
-	return "fooo"
-
-
-
-# new_my_class = MyClass
-# new_my_class.print_string()
-# foo().print_string()
-# MyClass = fooo
-# new_foo = MyClass
-# print(new_foo)
-
-# new_my_class = MyClass()
-# new_my_class.print_string()
-
-# def my_decorator(dec_str):
-# 	def wrapper(func):
-# 		# print dec_str
-# 		print "before my func"
-# 		func()
-# 		print "after my_func"
-# 	return wrapper
-
-
-# @my_decorator("to decorator")
-# def foo():
-# 	print "my_function"
-
-
-# foo()
-

+ 0 - 29
courses/python_for_begginers/tmp.py

@@ -1,29 +0,0 @@
-
-
-from typing import Any
-
-
-class Dad():
-	def __init__(self) -> None:
-		pass
-
-	def __call__(self, *args: Any, **kwds: Any) -> Any:
-		return True
-
-	def foo(self):
-		print("hello")
-
-class TestCall(Dad):
-	# def __init__(self):
-	# 	pass
-
-	# def __call__(self):
-	# 	print("Class __call__")
-		
-	__call__ = Dad.foo
-
-
-call = TestCall()
-call()
-print(isinstance(3, str))
-# print(call())

+ 79 - 11
courses/python_func/docstring_1.py

@@ -67,33 +67,101 @@ def rotate(lst: list[int | float], shift: int = 1) -> list[int | float] :
     'Функция выполняет циклический сдвиг списка на shift позиций вправо(shift>0) или влево(shift<0)'
     shifted_list = []
 
-    if shift > len(lst):
-        foo = shift%len(lst)
-        if shift < 0:
-            foo = - foo - 1
-    else:
+    if abs(shift) <= len(lst) or shift%len(lst) == 0:
         foo = shift
+    else:
+        if shift < 0:
+            foo = abs(shift)%len(lst)
+            foo *= -1
+        else:
+            foo = shift%len(lst)
 
-    if shift < 0:
+    if foo < 0:
         shifted_list.extend(lst[-foo:])
         shifted_list.extend(lst[:-foo])
-    elif shift > 0:
+    elif foo > 0:
         shifted_list.extend(lst[-foo:])
         shifted_list.extend(lst[:-foo])
     return shifted_list
 
 
+def ref_rotate(tpl: tuple[int | float, ...], shift: int = 1) -> tuple[int | float, ...] :
+    'Функция выполняет циклический сдвиг кортежа на shift позиций вправо (shift>0) или влево (shift<0)'
+    shifted_tuple = tuple()
+
+    if abs(shift) <= len(tpl) or shift%len(tpl) == 0:
+        foo = shift
+    else:
+        if shift < 0:
+            foo = abs(shift)%len(tpl)
+            foo *= -1
+        else:
+            foo = shift%len(tpl)
+
+    if foo < 0:
+        shifted_tuple = tpl[-foo:] + tpl[:-foo]
+    elif foo > 0:
+        shifted_tuple = tpl[-foo:] + tpl[:-foo]
+    return shifted_tuple
+
+
+def rotate_letter(letter: str, shift: int) -> str :
+    'Функция сдвигает символ letter на shift позиций'
+
+    code = ord(letter) - 97
+
+    if shift >= 0:
+        shift = shift - 26*(shift//26)
+        if (code + 97 + shift) >= 122:
+            return chr(code + 97 + shift - 26)
+        else:
+            return chr(code + 97 + shift)
+    else:
+        shift *= -1
+        shift = shift - 26*(shift//26)
+        if (code + 97 - shift) < 97:
+            return chr(code + 97 + 26 - shift)
+        else:
+            return chr(code + 97 - shift)
+
+
+def caesar_cipher(phrase: str, key: int) -> str:
+    'Шифр Цезаря'
+
+    my_str = ""
+    for i in phrase:
+        if i.isalpha():
+            my_str += rotate_letter(i, key)
+        else :
+            my_str += i
+    return my_str
+
+
+
+
 def main():
     # print(get_even.__doc__)
     # print(get_first_repeated_word.__doc__)
     # print(get_first_repeated_word.__annotations__)
     # print(get_first_repeated_word(['ab', 'ca', 'bc', 'ca', 'ab', 'bc']))
 
+    # print(rotate([1, 2, 3, 4, 5, 6], 2))
+    # print(rotate([1, 2, 3, 4, 5, 6], -10))
+    # print(rotate([1, 2, 3, 4, 5, 6, 7], 21))
+    # print(rotate([1, 2, 3, 4, 5, 6], -3))
+
+    # assert rotate([1, 2, 3, 4, 5, 6], 2) == [5, 6, 1, 2, 3, 4]
+    # assert rotate([1, 2, 3, 4, 5, 6], -3) == [4, 5, 6, 1, 2, 3]
+    # assert rotate([1, 2, 3, 4, 5, 6], -10) == [5, 6, 1, 2, 3, 4]
+    # assert rotate([1, 2, 3, 4, 5, 6, 7], 21) == [1, 2, 3, 4, 5, 6, 7]
+
+    # print(rotate_letter('a', 3))
+    # print(rotate_letter('d', -2))
+    # print(rotate_letter('w', -26))
+
+    print(caesar_cipher('leave out all the rest', -4))
 
-    print(rotate([1, 2, 3, 4, 5, 6], 2))
-    print(rotate([1, 2, 3, 4, 5, 6], -10))
-    print(rotate([1, 2, 3, 4, 5, 6, 7], 21))
-    print(rotate([1, 2, 3, 4, 5, 6], -3))
+    print('Good')
 
 if __name__ == '__main__':
     main()

+ 0 - 10
squqre_sum.py

@@ -1,10 +0,0 @@
-#Complete the square sum function so that it squares each number passed into it 
-#and then sums the results together.
-
-#For example, for [1, 2, 2] it should return 9 because 1^2 + 2^2 + 2^2 = 9.
-
-def square_sum(numbers):
-    return sum(i*i for i in numbers)
-
-print(square_sum([1, 2, 2]))
-print(square_sum([-1, -2]))

+ 0 - 13
tmp/tmp.py

@@ -1,13 +0,0 @@
-import socket
-
-def test():
-    sock = socket.socket()
-    sock.connect(('192.168.31.199', 1919))
-
-    data = sock.recv(50)
-    sock.close()
-
-    print(data)
-
-
-test()

+ 0 - 4
usb-test.py

@@ -1,4 +0,0 @@
-import usb
-import usb.core
-
-dev = usb.core.find(find_all=True)