diff --git a/Practice/gavrilova/1.py b/Practice/gavrilova/1.py new file mode 100644 index 0000000..a9273bb --- /dev/null +++ b/Practice/gavrilova/1.py @@ -0,0 +1,10 @@ +def length(lst): + if not lst: + return 0 + return 1 + length(lst[1:]) + + +a = [1, 2, 3] +l = length(a) +print("Длина списка равна: " + str(l)) + diff --git a/Practice/gavrilova/2.py b/Practice/gavrilova/2.py new file mode 100644 index 0000000..54a75b4 --- /dev/null +++ b/Practice/gavrilova/2.py @@ -0,0 +1,6 @@ +def myreversed(a): + return list[::-1] + +list = [123, 'abc', 'apple'] +x = myreversed(list) +print (x) \ No newline at end of file diff --git a/Practice/gavrilova/4.py b/Practice/gavrilova/4.py new file mode 100644 index 0000000..72d5223 --- /dev/null +++ b/Practice/gavrilova/4.py @@ -0,0 +1,11 @@ +def to_title(a): +# return a.title() + t = a.split(' ') + for i in range(1, len(t)): + t[i] = t[i][0].upper() + t[i][1:] + return ' '.join(t) + +s = 'orlov Ilya evgenyevich' +print (s) +s1 = to_title(s).capitalize() +print (s1) diff --git a/Practice/gavrilova/5.py b/Practice/gavrilova/5.py new file mode 100644 index 0000000..73d4df8 --- /dev/null +++ b/Practice/gavrilova/5.py @@ -0,0 +1,12 @@ +def count_symbol(a, s): + count = 0 + for i in a: + if i == s: + count += 1 + return count + +test_str = 'Hi, Elvis, I am here!' +simv = 'i' +n = count_symbol(test_str, simv) +print(f'Символ {simv} встречается в строке {test_str} {str(n)} раза') +#print ('Символ ' + simv + ' встречается в строке: ' + test_str + ' '+str(n)+' раз') diff --git a/Practice/gavrilova/7-1.py b/Practice/gavrilova/7-1.py new file mode 100644 index 0000000..7d180bb --- /dev/null +++ b/Practice/gavrilova/7-1.py @@ -0,0 +1,26 @@ +f1 = 'sourse.txt' +f2 = 'destination.txt' +try: + with open(f1, 'r') as file1: +# file1 = open(f1, 'r') + textfile1 = file1.read() +except Exception: + print(f'Файл {f1} не найден') +# print("Файл " + f1 + " не найден") +else: + try: + with open(f2, 'r') as file2: + print(f'Файл {f2} уже существует') +# file2 = open(f2, 'w') +# file2.write(textfile1) + except Exception: + with open(f2, 'w') as file2: + file2.write(textfile1) + print(textfile1) +# file1.close() +# file2.close() + with open(f2, 'r') as file2: +# file2 = open(f2, 'r') + textfile2 = file2.read() + print(textfile2) +# file2.close() \ No newline at end of file diff --git a/Practice/gavrilova/9.py b/Practice/gavrilova/9.py new file mode 100644 index 0000000..9f8107f --- /dev/null +++ b/Practice/gavrilova/9.py @@ -0,0 +1,56 @@ +class User: + + name = ' ' + age = 0 +# def __init__(self, name, age): +# self.name = name +# self.age = age + + def setName(self, name): + self.name = name + + def getName(self): + return self.name + + def setAge(self, age): + self.age = age + + def getAge(self): + return self.age + + +class Worker(User): + + salary = 0 +# def __init__(self, name, age, salary): +# super(Worker, self).__init__(name, age) +# self.salary = salary + + def setSalary(self, salary): + self.salary = salary + + def getSalary(self): + return self.salary + + +w1 = Worker() +w1.setName('John') +print(w1.getName()) +w1.setAge(25) +print(w1.getAge()) +w1.setSalary(1000) +print(w1.getSalary()) +w2 = Worker() +w2.setName('Jack') +print(w2.getName()) +w2.setAge(26) +print(w2.getAge()) +w2.setSalary(2000) +print(w2.getSalary()) +s = w1.getSalary() + w2.getSalary() +print(f'Сумма зарплат объектов John и Jack {s} ') +#w1 = Worker("John", 25, 1000) +#print(w1.salary) +#w2 = Worker("Jack", 26, 2000) +#print(w2.salary) +#print (w1.salary+w2.salary) \ No newline at end of file diff --git a/Practice/gavrilova/hw1.py b/Practice/gavrilova/hw1.py new file mode 100644 index 0000000..eb10377 --- /dev/null +++ b/Practice/gavrilova/hw1.py @@ -0,0 +1,24 @@ +def test1(a, b): # вывод на экран большего значения из двух чисел + if a > b: + print(a) + elif a < b: + print(b) + else: + print("Числа равны") + +def test2(a, b): # возврат бол7ьшего значения из двух чисел + if a > b: + return a + elif a < b: + return b + else: + return None + +a = int(input("Введите первое число ")) +b = int(input("Введите второе число ")) + +test1(a,b) +#test2(a,b) + +x = test2(a,b) #проверка возврвщаемого значения +print(x) \ No newline at end of file diff --git a/Practice/gavrilova/hw10.py b/Practice/gavrilova/hw10.py new file mode 100644 index 0000000..cfd6d8e --- /dev/null +++ b/Practice/gavrilova/hw10.py @@ -0,0 +1,8 @@ +dict = {'1': 'красный', '2': 'синий', '3': 'зеленый', '4': 'сиреневый', '5': 'голубой'} + +line = "Камни имеют цвета: рубин 1, сапфир 2, изумруд 3, аметист 4, топаз 5, танзанит 4" + +for i in dict.keys(): + line = line.replace(i, dict[i]) + +print(line) \ No newline at end of file diff --git a/Practice/gavrilova/hw11.py b/Practice/gavrilova/hw11.py new file mode 100644 index 0000000..6a12b6a --- /dev/null +++ b/Practice/gavrilova/hw11.py @@ -0,0 +1,27 @@ +import random + +def del_column(lst, x): + for i in range(len(lst)): + for j in reversed(range(len(lst[i]))): + if lst[i][j] == x: + for k in range(len(lst)): + del lst[k][j] + +lst = [ + [1, 1, 2], + [1, 2, 1], + [1, 1, 1] +] + +print(*lst, sep='\n') +x = int(input('Введите число: ')) +del_column(lst, x) +print(*lst, sep='\n') + +row = int(input('Введите кол-во строк: ')) +column = int(input('Введите кол-во столбцов: ')) +lst1 = [[random.randrange(1, 10) for _ in range(column)] for _ in range(row)] +print(*lst1, sep='\n') +x = int(input('Введите число: ')) +del_column(lst1, x) +print(*lst1, sep='\n') \ No newline at end of file diff --git a/Practice/gavrilova/hw12.py b/Practice/gavrilova/hw12.py new file mode 100644 index 0000000..3643b6b --- /dev/null +++ b/Practice/gavrilova/hw12.py @@ -0,0 +1,27 @@ +import time +import random + +class Man: + + def __init__(self, name): + self.name = name + + def solve_task(self): + print("I'm not ready yet") + +class Pupil(Man): + + def __init__(self, name): + self.name = name + + def solve_task(self): + time.sleep(random.randint(3, 6)) + super().solve_task() + +m = Man('Marya') +print(f'Are you ready {m.name}?') +m.solve_task() + +p = Pupil('Evgeniy') +print(f'And you {p.name}?') +p.solve_task() \ No newline at end of file diff --git a/Practice/gavrilova/hw13.py b/Practice/gavrilova/hw13.py new file mode 100644 index 0000000..8b22879 --- /dev/null +++ b/Practice/gavrilova/hw13.py @@ -0,0 +1,37 @@ +import tempfile +import os + +class WrapStrToFile: + + def __init__(self): + self.filepath = tempfile.mktemp(suffix='.txt', dir='.') + + @property + def content(self): + try: + with open(self.filepath, 'r') as f: + data = f.read() + except Exception: + data = "Файл еще не существует" + return data + + @content.setter + def content(self, value): + with open(self.filepath, 'w') as f: + f.write(str(value)) + + @content.deleter + def content(self): + print('Файл удален') +# os.close(fd) + os.unlink(self.filepath) + + +wstf = WrapStrToFile() +print(wstf.filepath) +print(wstf.content) +wstf.content = 'Привет' +print(wstf.content) +wstf.content = 'Привет еще раз' +print(wstf.content) +del wstf.content \ No newline at end of file diff --git a/Practice/gavrilova/hw2.py b/Practice/gavrilova/hw2.py new file mode 100644 index 0000000..9747f57 --- /dev/null +++ b/Practice/gavrilova/hw2.py @@ -0,0 +1,42 @@ +#работа с классами +class Tank: + + caption = "" + length = 0 + speed = 0 + armament = "" + + def say_caption(self): + print (f"Наименование танка {self.caption}") + + def say_length(self): + print (f"Длина танка {self.length}") + + def say_speed(self): + print (f"Подвижность танка {self.speed}") + + def say_armament(self): + print (f"Вооружение танка {self.armament}") + +t34 = Tank() +t34.caption = "Т34" +t34.length = 5964 +t34.speed = 54 +t34.armament = "76-мм танковая пушка ф-34" + +tiger = Tank() +tiger.caption = "Tiger" +tiger.length = 8450 +tiger.speed = 45 +tiger.armament = "88-мм KwK 36" + +t34.say_caption() +t34.say_length() +t34.say_speed() +t34.say_armament() + + +tiger.say_caption() +tiger.say_length() +tiger.say_speed() +tiger.say_armament() \ No newline at end of file diff --git a/Practice/gavrilova/hw3.py b/Practice/gavrilova/hw3.py new file mode 100644 index 0000000..4bf84d9 --- /dev/null +++ b/Practice/gavrilova/hw3.py @@ -0,0 +1,32 @@ +def fun(a): + y = y.join(a) + print(a) + + +def get_arg(arg): + x = [] + while not arg.lower() == "stop": + arg = input('Введите число ') + if arg.isnumeric(): + x.append(arg) + + elif arg != "stop": + print("Некорректный ввод") +# else: +# if arg == "stop": +# pass +# else: +# print("Некорректный ввод") + return x + + + # print(arg) + +arg = 0 +y = '' +#x = [] +x = get_arg('x') +y = y.join(x) +print(y) +#fun(x) + diff --git a/Practice/gavrilova/hw4.py b/Practice/gavrilova/hw4.py new file mode 100644 index 0000000..2facfb3 --- /dev/null +++ b/Practice/gavrilova/hw4.py @@ -0,0 +1,10 @@ +def check_palindrome(a): + a = a.lower() + b = a[::-1] + if a == b: + print(a, "Палиндром") + else: + print(a, "Не палиндром") + +x = input("Введите слово: ") +check_palindrome(x) \ No newline at end of file diff --git a/Practice/gavrilova/hw5.py b/Practice/gavrilova/hw5.py new file mode 100644 index 0000000..7cb05be --- /dev/null +++ b/Practice/gavrilova/hw5.py @@ -0,0 +1,22 @@ +import random + +x=0 +number = random.randint(1, 10) + +while True: + x = input("Введите число в диапазоне от 1 до 10:") + + if not x.isnumeric(): + print("Вы ввели не число") + break + + x = int(x) + + if x > number: + print("Загаданное число меньше") + elif x < number: + print("Загаданное число больше") + else: +# x == number: + print("Вы угадали") + break \ No newline at end of file diff --git a/Practice/gavrilova/hw6.py b/Practice/gavrilova/hw6.py new file mode 100644 index 0000000..80787ca --- /dev/null +++ b/Practice/gavrilova/hw6.py @@ -0,0 +1,13 @@ +lst = [] + +for x in range(1, 101): + if x % 15 == 0: + lst.append('FizzBuzz') + elif x % 3 == 0: + lst.append('Fizz') + elif x % 5 == 0: + lst.append('Buzz') + else: + lst.append(x) + +print(lst) \ No newline at end of file diff --git a/Practice/gavrilova/hw7.py b/Practice/gavrilova/hw7.py new file mode 100644 index 0000000..d10a925 --- /dev/null +++ b/Practice/gavrilova/hw7.py @@ -0,0 +1,3 @@ +x = input("Введите число ") +for i in range(len(x)): + print(f'{i+1} цифра равна {x[i]}') diff --git a/Practice/gavrilova/hw8.py b/Practice/gavrilova/hw8.py new file mode 100644 index 0000000..cb8df1e --- /dev/null +++ b/Practice/gavrilova/hw8.py @@ -0,0 +1,15 @@ +def sort(a): + for i in range(len(a)): + n = i +# print("i=",i) + for j in range(i + 1,len(a)): +# print("j=",j) + if a[j] < a[n]: + n = j + a[i], a[n] = a[n], a[i] + +аrr = list(input("Введите последовательность чисел ")) + +print(аrr) +sort(аrr) +print(аrr) \ No newline at end of file diff --git a/Practice/gavrilova/hw9.py b/Practice/gavrilova/hw9.py new file mode 100644 index 0000000..c8f9c5c --- /dev/null +++ b/Practice/gavrilova/hw9.py @@ -0,0 +1,25 @@ +def fun(f, f_new, before, after): + for line in f: + line_new = line.replace(before, after) + print(line_new) + f_new.write(line_new) + + +with open('text.txt', 'w') as f: + f.write(input('Введите строку ')) + + +while True: + x = input('Для замены пробелов на табуляцию введите t, для замены табуляции на пробелы введите s ') + if x == 't': + with open('text.txt', 'r') as f, \ + open('text_t.txt', 'w') as f_t: + fun(f, f_t, ' ', '\t') + break + elif x == 's': + with open('text.txt', 'r') as f, \ + open('text_s.txt', 'w') as f_s: + fun(f, f_s, '\t', ' ') + break + else: + print('Некорректный ввод') diff --git a/Practice/gavrilova/text.txt b/Practice/gavrilova/text.txt new file mode 100644 index 0000000..5d65bb9 --- /dev/null +++ b/Practice/gavrilova/text.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Practice/gavrilova/text_s.txt b/Practice/gavrilova/text_s.txt new file mode 100644 index 0000000..97afd6a --- /dev/null +++ b/Practice/gavrilova/text_s.txt @@ -0,0 +1 @@ +jkkgkg jljljlkj \ No newline at end of file diff --git a/Practice/gavrilova/text_t.txt b/Practice/gavrilova/text_t.txt new file mode 100644 index 0000000..6f9be9b --- /dev/null +++ b/Practice/gavrilova/text_t.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Practice/~$README.md b/Practice/~$README.md new file mode 100644 index 0000000..b79fe51 Binary files /dev/null and b/Practice/~$README.md differ