-
Notifications
You must be signed in to change notification settings - Fork 0
Gavrilova #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Gavrilova #11
Conversation
|
aaa |
| # continue | ||
| else: | ||
| print("Некорректный ввод") | ||
| return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше сделать x локальной переменной. Чем меньше в функции зависимостей от глобальных переменных - тем она более универсальная и гибкая. Например, ее проще импортировать из других модулей.
arg достаточно указать как локальную переменную, особого смысла в нем, как в аргументе функции, нет.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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), никак, по сути, не используется.
| # print("j=",j) | ||
| if a[j] < a[n]: | ||
| n = j | ||
| a[i], a[n] = a[n], a[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Стало лучше. Но не стоит выполнять замену для каждого элемента, который меньше i-го. Во внутреннем цикле for мы только находим минимальный элемент от i + 1 до конца списка. А замену i-го элемента на n-й должны делать уже вне этого внутреннего цикла (как описано в условии задачи про шаги алгоритма).
Кстати, использование n для ссылки одновременно на i-й элемент и на j-й элемент несколько запутывает код.
|
|
||
| class Pupil(Man): | ||
|
|
||
| def __init__(self, name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__init__ уже можно не указывать. Наследование позволяет Pupil переиспользовать методы Man.
Practice/gavrilova/7-1.py
Outdated
| print("Файл " + f1 + " не найден") | ||
| else: | ||
| try: | ||
| file2 = open('destination.txt', 'w') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
При таком способе открытия, если файл уже существует, то он перезапишется, и исключения, как требуется по заданию, не произойдет.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно проще:
with open(f2, 'x') as file2:т.е. открыть в режиме 'x'.
Этот способ как раз и приведет к исключению, если файл уже существует.
No description provided.