-
Notifications
You must be signed in to change notification settings - Fork 56
HW2_Gorbarenko #5
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?
Changes from all commits
65f100e
0e7106d
19000e8
30807ce
734664d
fc8451d
2b3dd3b
10fdad8
61f1359
a35ac1d
91469a4
5d42581
bbe2e17
90bb6ca
ce3e583
9d96a71
2f64922
51d1661
32d1cba
6d0f763
adf56f5
31ac7da
57fecc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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* | ||
|
||
### Описание скрипта | ||
|
||
calculator.py - скрипт, позволяющий выполнять сложение, вычитание, умножение и деление двух чисел. | ||
|
||
Ввод осуществляется в виде строки | ||
|
||
`a _ b` | ||
|
||
где `a` и `b` - числа, | ||
|
||
`_` - один из четырёх символов: `+ - * /`, соответствующих арифметическим операциям сложения, вычитания, умножения и деления. | ||
|
||
Все три элемента должны быть разделены пробелами. | ||
|
||
Пожалуйста, не делите на ноль! :fearful: | ||
|
||
#### Наша прекрасная команда | ||
|
||
Алиса Кабалина | ||
|
||
Дарья Соколова | ||
|
||
Кирилл Петриков | ||
|
||
Татьяна Лисица | ||
|
||
Анастасия Горбаренко, team leader | ||
|
||
 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
a,b,c = input().split() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь и везде ниже. Названия переменных num1, operator, num2 = input().split() |
||
if ("." in a) or ("." in c): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Обрабатывать сразу 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это и после функций нужно было завернуть в функцию Функция main внутри себя должна принимать входное выражение, отдавать его на вычисление соответствующей функции, получать результат и печатать его на экран. Каждая из 4 функций лишь принимает определенное выражение от главной функции, вычисляет его и возвращает результат главной функции. |
||
|
||
def teilen(a,b): | ||
return(a / b) | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def delta(a, b): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return a - b | ||
|
||
def sokol_sum(a,b): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return a+b | ||
|
||
def multi(a, b): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В целом норм, но лучше тогда уж |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И вот это должно было быть в Функция 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) |
||
|
||
|
||
|
||
|
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.
Вроде эти строчки на английском, а дальше идет на русском ... как-то странно ))