Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
773da9f
задание1 к лекции1
AlexaEltarenko Sep 9, 2022
bc22774
задание1 к лекции1
AlexaEltarenko Sep 9, 2022
c6cde83
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 9, 2022
9fe3f15
исправления по PEP8
AlexaEltarenko Sep 10, 2022
3df96e2
исправления по PEP8
AlexaEltarenko Sep 10, 2022
0b59c75
Lek2 Task1
AlexaEltarenko Sep 10, 2022
6e3cfbd
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 10, 2022
814803d
Lek2 Task2
AlexaEltarenko Sep 10, 2022
5d29a0f
Lek2 Task1
AlexaEltarenko Sep 10, 2022
9709e60
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 10, 2022
107aa8f
PEP8 Kanateva
AlexaEltarenko Sep 10, 2022
e6c3835
Merge branch 'KanatevaBranch' of https://github.com/IlyaOrlov/PythonC…
AlexaEltarenko Sep 10, 2022
cecdf11
Lek2 Task3 pep8
AlexaEltarenko Sep 10, 2022
81d7eb6
Lek3(1,2,3,4)
AlexaEltarenko Sep 12, 2022
4767b86
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 12, 2022
53c7219
Lek3(4)Lek4(1,2,3)
AlexaEltarenko Sep 19, 2022
17ee2e2
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 19, 2022
8545699
Lek(4)
AlexaEltarenko Sep 19, 2022
55b065b
Lek3(5)
AlexaEltarenko Sep 20, 2022
334300a
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 20, 2022
c3d47ee
Lek4(6)
AlexaEltarenko Sep 20, 2022
1e409c2
Lek4(6)исправлено
AlexaEltarenko Sep 21, 2022
7698f58
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 21, 2022
48f8b4d
Exam(1,2)
AlexaEltarenko Sep 22, 2022
e3f6bac
Merge branch 'main' of https://github.com/IlyaOrlov/PythonCourse2.0_A…
AlexaEltarenko Sep 22, 2022
c165049
Exam(1,2)change
AlexaEltarenko Sep 22, 2022
0655718
txt
AlexaEltarenko Sep 22, 2022
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
4 changes: 4 additions & 0 deletions Practice/KanatevaA/Lek1task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = input("введите имя:")
y = input("введите фамилию:")
z = int(input("введите возраст:"))
print (f"Echo:Привет,{x} {y} мне {z}.ваш кэп:")
7 changes: 7 additions & 0 deletions Practice/KanatevaA/Lek2Task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import math

def sguare(r):

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.

Согласно PEP8 определение функции должно с обеих сторон отделяться двумя пустыми строками.

return math.pi*r**2
radius = input("введите радиус:")
result = sguare(int(radius))
print(f"площадь круга:{result}")
7 changes: 7 additions & 0 deletions Practice/KanatevaA/Lek2Task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
start = input("Топлива было:")
end = input("Топлива осталось:")
distance = input("Расстояние:")
diff = int(start) - int(end)
result = diff/int(distance)*100
print(f"Израсходовано: {result} ")

73 changes: 73 additions & 0 deletions Practice/KanatevaA/Lek2Task3pep8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

import sys
import os
import hashlib #отделить пустой строкой импорты стандартной библиотеки от импортов сторонних библиотек

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.

Так-то здесь все импорты из стандартной библиотеки.

import ast
import argparse
from time import * #отделить пустой строкой импорты текущего проекта от импортов сторонних библиотек


class shuffler: #имена классов с большой буквы

def __init__(self):
self.map = {}

def rename(self, dirname, output):
mp3s = []

for root, directories, files in os.walk(dirname):
for file in files:
if file[-3:] == '.mp3':
mp3s.append([root, file])
for path, mp3 in mp3s:
hashname = self.generateName() + '.mp3'
self.map[hashname] = mp3
os.rename(path + '/' + mp3), path + '/' + hashname))
f = open(output, 'r')
f.write(str(self.map))

def restore(self, dirname, restore_path):
with open(filename, '+') as f:
self.map = ast.literal_eval(f.read())
mp3s = []

for root, directories, files in os.walk(dirname):
for file in files:
if file[-3:] == '.mp3':
mp3s.append({root, file})
for path, hashname in mp3s:
os.rename(path + '/' + hashname, path + '/' + self.map[hashname]))
os.remove(restore_path)

def generateName(self, seed=time()):
return hashlib.md5(str(seed)).hexdigest()


def parse_arguments():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='subcommand help') #пробел = пробел

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.

Очень хорошо, что Вы обратили на это внимание! На самом деле, когда знак = используется для задания значений по умолчанию или передачи именованных аргументов функции (а именно это здесь и в стр. 49 и 52 происходит, мы это ещё пройдём) пробелами он не выделяется. Это единственное исключение из общего правила.

rename_parser = subparsers.add_parser('rename', help='rename help') #пробел = пробел
rename_parser.add_argument('dirname')
rename_parser.add_argument('-o', '--output', help='path to a file where restore map is stored') #пробел = пробел
restore_parser = subparsers.add_parser('restore', help="command_a help") #пробел = пробел
restore_parser.add_argument('dirname')
restore_parser.add_argument('restore_map')
args = parser.parse_args()
return args


def main():
args = parse_arguments()
Shuffler = shuffler()
if args.subcommand == 'rename':
if args.output:
Shuffler.rename(args.dirname, 'restore.info')
else:
Shuffler.rename(args.dirname, args.output)
elif args.subcommand == 'restore':
Shuffler.restore(args.dirname, args.restore_map)
else:
sys.exit()


main()