Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions HW2_Gorbarenko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# HW2_Git_and_python from Gorbarenko team
*This is the repo for the second homework of the BI Python 2023 course*

Choose a reason for hiding this comment

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

Вроде эти строчки на английском, а дальше идет на русском ... как-то странно ))


### Описание скрипта

calculator.py - скрипт, позволяющий выполнять сложение, вычитание, умножение и деление двух чисел.

Ввод осуществляется в виде строки

`a _ b`

где `a` и `b` - числа,

`_` - один из четырёх символов: `+ - * /`, соответствующих арифметическим операциям сложения, вычитания, умножения и деления.

Все три элемента должны быть разделены пробелами.

Пожалуйста, не делите на ноль! :fearful:

#### Наша прекрасная команда

Алиса Кабалина

Дарья Соколова

Кирилл Петриков

Татьяна Лисица

Анастасия Горбаренко, team leader

![alt_text](https://github.com/KirPetrikov/HW2_Git_and_python/blob/HW2_Petrikov/HW2_Gorbarenko/photo.jpg?raw=true)
39 changes: 39 additions & 0 deletions HW2_Gorbarenko/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

a,b,c = input().split()

Choose a reason for hiding this comment

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

Здесь и везде ниже. Названия переменных a, b, c абсолютно не информативны.

num1, operator, num2 = input().split()

if ("." in a) or ("." in c):

Choose a reason for hiding this comment

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

Обрабатывать сразу 2 числа тут плохо. Попробуйте протестировать на вот таком инпуте:
1,2 + 1.2

a = float(a)
c = float(c)
elif ("," in a) or ("," in c):
a = float(a.replace(',','.'))
c = float(c.replace(',','.'))
else:
a = int(a)
c = int(c)
Comment on lines +2 to +11
Copy link

@SidorinAnton SidorinAnton Sep 18, 2023

Choose a reason for hiding this comment

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

Это и после функций нужно было завернуть в функцию main. По заданию:

Функция main внутри себя должна принимать входное выражение, отдавать его на вычисление соответствующей функции, получать результат и печатать его на экран. Каждая из 4 функций лишь принимает определенное выражение от главной функции, вычисляет его и возвращает результат главной функции.


def teilen(a,b):
return(a / b)
Comment on lines +13 to +14

Choose a reason for hiding this comment

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

  1. teilen? Почему не division? ))
  2. В return тут не нужны скобки.


def delta(a, b):

Choose a reason for hiding this comment

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

delta? Почему не substraction? ))

return a - b

def sokol_sum(a,b):

Choose a reason for hiding this comment

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

sokol тут лишний )))
Можно назвать, например, addition

return a+b

def multi(a, b):

Choose a reason for hiding this comment

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

В целом норм, но лучше тогда уж multiplication ))

return(a * b)


if (b == "+"): #sokol_sum
print(sokol_sum(a,c))
elif (b == "-"): #delta
print(delta(a,c))
elif (b == "*"): #multi
print(multi(a,c))
elif (b == "/") : #teilen
print(teilen(a,c))
else:
print("I dont know what it is")
Comment on lines +26 to +35
Copy link

@SidorinAnton SidorinAnton Sep 18, 2023

Choose a reason for hiding this comment

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

И вот это должно было быть в main.

Функция main внутри себя должна принимать входное выражение, отдавать его на вычисление соответствующей функции, получать результат и печатать его на экран. Каждая из 4 функций лишь принимает определенное выражение от главной функции, вычисляет его и возвращает результат главной функции.

Ну и плюс в ифах тут не нужны скобки. Вообще я бы сделал вот так:

# С учетом правок по названиям
result = "I dont know what it is"

if operator == "+":
    result = addition(num1, num2)
elif operator == "-":
    result = substraction(num1, num2)
elif operator == "*":
    result = multiplication(num1, num2)
elif operator == "/":
    result = division(num1, num2)

print(result)





Binary file added HW2_Gorbarenko/photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.