Skip to content

020_lesson#2

Open
ikrugloff wants to merge 9 commits into020_lessonfrom
master
Open

020_lesson#2
ikrugloff wants to merge 9 commits into020_lessonfrom
master

Conversation

@ikrugloff
Copy link
Owner

My first HW on GH.

Copy link

@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.

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

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

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

Choose a reason for hiding this comment

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

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

if operator == '+':
sumab = a + b
print(f'{a} + {b} = {sumab}')
operator = input('Please input an operator: ')

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

even += 1
else:
odd += 1
num = num // 10

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

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

Отлично

n = int(input())
e = 1
s = 0
for i in range(n):

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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


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

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

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

from random import random

Choose a reason for hiding this comment

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

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

s += i
m = n * (n + 1) // 2
print(s)
print(m) No newline at end of file

Choose a reason for hiding this comment

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

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

Copy link
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 сделать, согласен.

Choose a reason for hiding this comment

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

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

count = 0
for i in range(1,n+1):
m = int(input("Number " + str(i) + ": "))
while m > 0:

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

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

Отлично

Copy link

@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.

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

if operator == '+':
sumab = a + b
print(f'{a} + {b} = {sumab}')
operator = input('Please input an operator: ')

Choose a reason for hiding this comment

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

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

n = int(input())
e = 1
s = 0
for i in range(n):

Choose a reason for hiding this comment

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

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


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

Choose a reason for hiding this comment

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

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

s += i
m = n * (n + 1) // 2
print(s)
print(m) No newline at end of file

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