Skip to content

020_lesson#2

Open
ikrugloff wants to merge 9 commits into
020_lessonfrom
master
Open

020_lesson#2
ikrugloff wants to merge 9 commits into
020_lessonfrom
master

Conversation

@ikrugloff
Copy link
Copy Markdown
Owner

My first HW on GH.

Copy link
Copy Markdown

@Dzhoker1 Dzhoker1 left a comment

Choose a reason for hiding this comment

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

Оставил комментарии по коду

Comment thread task_01.py
print('Enter a sign of operation (+, -, *, / or 0 for exit) and 2 integer digits')

operator = input('Please input an operator: ')
if operator != str(0):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно просто ноль в кавычках написать.

Comment thread task_01.py
if operator == '+':
sumab = a + b
print(f'{a} + {b} = {sumab}')
operator = input('Please input an operator: ')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно было вынести эту строчку, чтобы 4 раза не повторять

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Вынести, что-то типа функции написать имеете ввиду?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нет. Один раз написать, после всех if Зачем в каждый вставлять. Раз везде нужен, пишите один раз вне if

Comment thread task_02.py
even += 1
else:
odd += 1
num = num // 10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут отлично, а на блок-схеме эта строчка сразу в двух блоках.

Comment thread task_03.py
@@ -1,11 +0,0 @@
# 3. Сформировать из введенного числа обратное по порядку входящих
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отлично

Comment thread task_04.py
n = int(input())
e = 1
s = 0
for i in range(n):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если вам нужен цикл, но не нужна переменная, то вместо i используйте _

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Про этот чит в книге Любановича читал).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Да. Читаешь код и сразу понятно зачем нужен цикл )))

Comment thread task_05.py

for i in range(32, 128):
print('{0:4d}-{1}'.format(i, chr(i)), end='')
if i % 10 == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В первой строке 9 пар (((

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

А можете объяснить, как корректный вывод сделать? Самостоятельно не осилил.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Объясняю, меняете ноль на один в этой строке. Как я сделал на уроке во время разбора ДЗ.

Comment thread task_06.py
# меньше загаданного введенное пользователем число. Если за 10
# попыток число не отгадано, то вывести его.

from random import random
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отлично.
Не забывайте добавлять пустую строку после import

Comment thread task_07.py
s += i
m = n * (n + 1) // 2
print(s)
print(m) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Посчитано отлично. Но почему просто вывод чисел. А если ответы огромные и пользователь сам не может сравнить их?)))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Можно было return True / False сделать, согласен.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Да, всего лишь вывести результат сравнения переменных

Comment thread task_08.py
count = 0
for i in range(1,n+1):
m = int(input("Number " + str(i) + ": "))
while m > 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Чуть не туда поставили стрелочки на блок-схеме. А код отличный

Comment thread task_09.py
@@ -1,18 +0,0 @@
# 9. Среди натуральных чисел, которые были введены, найти
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отлично

Copy link
Copy Markdown

@Dzhoker1 Dzhoker1 left a comment

Choose a reason for hiding this comment

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

Ответил на ваши вопросы

Comment thread task_01.py
if operator == '+':
sumab = a + b
print(f'{a} + {b} = {sumab}')
operator = input('Please input an operator: ')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нет. Один раз написать, после всех if Зачем в каждый вставлять. Раз везде нужен, пишите один раз вне if

Comment thread task_04.py
n = int(input())
e = 1
s = 0
for i in range(n):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Да. Читаешь код и сразу понятно зачем нужен цикл )))

Comment thread task_05.py

for i in range(32, 128):
print('{0:4d}-{1}'.format(i, chr(i)), end='')
if i % 10 == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Объясняю, меняете ноль на один в этой строке. Как я сделал на уроке во время разбора ДЗ.

Comment thread task_07.py
s += i
m = n * (n + 1) // 2
print(s)
print(m) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Да, всего лишь вывести результат сравнения переменных

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants