Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fc049d7
домашнее задание 1
GavrilovaMA Aug 31, 2021
0d77445
домашнее задание 1
GavrilovaMA Aug 31, 2021
ccc700c
домашнее задание 2
GavrilovaMA Aug 31, 2021
2e86d2e
домашнее задание 4
GavrilovaMA Aug 31, 2021
0a15f1f
домашнее задание 3
GavrilovaMA Aug 31, 2021
8d4dd37
домашнее задание 5
GavrilovaMA Aug 31, 2021
ed2d42b
домашнее задание 1
GavrilovaMA Sep 3, 2021
393e130
домашнее задание 3
GavrilovaMA Sep 3, 2021
8cb9df2
домашнее задание 4
GavrilovaMA Sep 3, 2021
18248c5
домашнее задание 3
GavrilovaMA Sep 3, 2021
5a765d4
домашнее задание 1
GavrilovaMA Sep 3, 2021
fe05599
домашнее задание 1
GavrilovaMA Sep 3, 2021
f7fefdd
домашнее задание 6
GavrilovaMA Sep 7, 2021
bb4d96b
домашнее задание 7
GavrilovaMA Sep 7, 2021
c496e54
домашнее задание 8
GavrilovaMA Sep 8, 2021
a9a2015
домашнее задание 9
GavrilovaMA Sep 8, 2021
ea32525
домашнее задание 9
GavrilovaMA Sep 8, 2021
a02d8e9
домашнее задание 10
GavrilovaMA Sep 8, 2021
29bbeb6
домашнее задание 3
GavrilovaMA Sep 9, 2021
cf108a4
домашнее задание 6
GavrilovaMA Sep 9, 2021
69d497b
домашнее задание 7
GavrilovaMA Sep 9, 2021
b249606
домашнее задание 7
GavrilovaMA Sep 9, 2021
d815b04
домашнее задание 6
GavrilovaMA Sep 9, 2021
dbd92f2
домашнее задание 12
GavrilovaMA Sep 22, 2021
35afaeb
домашнее задание 11
GavrilovaMA Sep 22, 2021
3b39b99
домашнее задание 13
GavrilovaMA Sep 23, 2021
abba903
экзамен 1
GavrilovaMA Sep 24, 2021
10cc86d
экзамен 2
GavrilovaMA Sep 24, 2021
ffaf7f0
экзамен 4
GavrilovaMA Sep 24, 2021
205b3ca
экзамен 4
GavrilovaMA Sep 24, 2021
0c4d6e5
экзамен 7
GavrilovaMA Sep 24, 2021
71e8ae8
экзамен 9
GavrilovaMA Sep 24, 2021
1484c82
экзамен 5
GavrilovaMA Sep 24, 2021
63422fb
экзамен 1
GavrilovaMA Sep 27, 2021
091d391
экзамен 2
GavrilovaMA Sep 27, 2021
ef71946
экзамен 5
GavrilovaMA Sep 27, 2021
8da7a1b
экзамен 5
GavrilovaMA Sep 27, 2021
e18ac04
экзамен 7
GavrilovaMA Sep 27, 2021
d163b10
экзамен 5
GavrilovaMA Sep 27, 2021
82ff4a9
экзамен 5
GavrilovaMA Sep 27, 2021
824e466
экзамен 9
GavrilovaMA Sep 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Practice/gavrilova/1.py
Original file line number Diff line number Diff line change
@@ -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))

6 changes: 6 additions & 0 deletions Practice/gavrilova/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def myreversed(a):
return list[::-1]

list = [123, 'abc', 'apple']
x = myreversed(list)
print (x)
11 changes: 11 additions & 0 deletions Practice/gavrilova/4.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions Practice/gavrilova/5.py
Original file line number Diff line number Diff line change
@@ -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)+' раз')
26 changes: 26 additions & 0 deletions Practice/gavrilova/7-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
f1 = 'sourse.txt'
Comment thread
IlyaOrlov marked this conversation as resolved.
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()
56 changes: 56 additions & 0 deletions Practice/gavrilova/9.py
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions Practice/gavrilova/hw1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def test1(a, b): # вывод на экран большего значения из двух чисел
if a > b:
print(a)
elif a < b:
print(b)
else:
Comment thread
IlyaOrlov marked this conversation as resolved.
print("Числа равны")

def test2(a, b): # возврат бол7ьшего значения из двух чисел
if a > b:
return a
elif a < b:
return b
else:
Comment thread
IlyaOrlov marked this conversation as resolved.
return None

a = int(input("Введите первое число "))
b = int(input("Введите второе число "))

test1(a,b)
#test2(a,b)

x = test2(a,b) #проверка возврвщаемого значения
print(x)
8 changes: 8 additions & 0 deletions Practice/gavrilova/hw10.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions Practice/gavrilova/hw11.py
Original file line number Diff line number Diff line change
@@ -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')
27 changes: 27 additions & 0 deletions Practice/gavrilova/hw12.py
Original file line number Diff line number Diff line change
@@ -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):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__init__ уже можно не указывать. Наследование позволяет Pupil переиспользовать методы Man.

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()
37 changes: 37 additions & 0 deletions Practice/gavrilova/hw13.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions Practice/gavrilova/hw2.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions Practice/gavrilova/hw3.py
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше сделать x локальной переменной. Чем меньше в функции зависимостей от глобальных переменных - тем она более универсальная и гибкая. Например, ее проще импортировать из других модулей.
arg достаточно указать как локальную переменную, особого смысла в нем, как в аргументе функции, нет.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С x теперь все ОК. Остался arg.



# print(arg)

arg = 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот arg и arg в функции get_arg - абсолютно разные переменные. arg в стр.25 вообще не нужен, а arg в функции get_arg надо сделать локальной переменной, убрав из списка параметров функции. Т.к. то, что в эту функцию передается (в стр. 28), никак, по сути, не используется.

y = ''
#x = []
x = get_arg('x')
y = y.join(x)
print(y)
#fun(x)

10 changes: 10 additions & 0 deletions Practice/gavrilova/hw4.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions Practice/gavrilova/hw5.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions Practice/gavrilova/hw6.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions Practice/gavrilova/hw7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = input("Введите число ")
for i in range(len(x)):
print(f'{i+1} цифра равна {x[i]}')
Loading