-
Notifications
You must be signed in to change notification settings - Fork 56
HW2_Grigoriants #3
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
266fb2f
a735b21
6499381
8becf4c
91b453f
d07d5f2
f1b4b30
ff3c40c
11074e7
07a6dcb
1f6c822
f1c15c8
f08c02a
cf66dc5
405080f
151d7bf
a9aaa62
037bb9f
b41e261
dfb9c82
72090cf
bcdecee
693f0d0
a4016a0
48ac7a9
97d4619
fc9f004
db1237c
45a4ffe
573a274
8499af9
c6ff335
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,13 @@ | ||
# HW2_Git_and_python by Git Dream Team | ||
Наша команда обеспечила Github комьюнити новейшим вычислительным механизмом. С её помощью школьная арифметика больше не создаст ни для кого проблем! Программа принимает на вход строку с некоторым математическим выражением и выводит число - результат вычисления этого выражения. | ||
|
||
# Состав команды: | ||
* Виктория Орлова | ||
* Анастасия Петухова | ||
* Мария Лукина | ||
* Елизавета Чевокина | ||
* Владимир Григорянц - наш ***тимлид*** | ||
|
||
Инсайд с нашего собрания: | ||
|
||
 |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||
### This will be our great calculator. Please contribute by writing one of the functions | ||||||||||||||
def division(num1, num2): #division of numbers | ||||||||||||||
if num2 == 0: | ||||||||||||||
return "Dude, for real?" | ||||||||||||||
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. Когда вы проводите операции над числами, вы ожидаете, что на выходе получите другое число. Здесь же вернется строка. В таких ситуациях лучше останавливать программу и выбрасывать ошибку. Например:
Suggested change
С модулями sys и os вы еще познакомитесь:) |
||||||||||||||
else: | ||||||||||||||
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. else здесь не нужен |
||||||||||||||
return num1 / num2 | ||||||||||||||
|
||||||||||||||
def plus(num1, num2): #sum of numbers | ||||||||||||||
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 num1 + num2 | ||||||||||||||
|
||||||||||||||
def multiplication(num1, num2): #multiplication of numbers | ||||||||||||||
return num1 * num2 | ||||||||||||||
|
||||||||||||||
def minus (num1, num2): | ||||||||||||||
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.
Suggested change
|
||||||||||||||
return num1 - num2 | ||||||||||||||
|
||||||||||||||
def main(): #accepts input, transmits to corresponding function and returns answer | ||||||||||||||
my_string = input() | ||||||||||||||
num1 = float(my_string.split()[0]) | ||||||||||||||
num2 = float(my_string.split()[2]) | ||||||||||||||
sign = my_string.split()[1] | ||||||||||||||
Comment on lines
+19
to
+21
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. в целом рабочий вариант, но есть переиспользование кода, лучше было бы сделать так:
Suggested change
|
||||||||||||||
if sign == "+": | ||||||||||||||
ans = plus(num1, num2) | ||||||||||||||
elif sign == "-": | ||||||||||||||
ans = minus(num1, num2) | ||||||||||||||
elif sign == "*": | ||||||||||||||
ans = multiplication(num1, num2) | ||||||||||||||
elif sign == "/": | ||||||||||||||
ans = division(num1, num2) | ||||||||||||||
return ans | ||||||||||||||
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. Обратите внимание: по PEP8 после функции идет пропуск 2х строк. |
||||||||||||||
answer = main() | ||||||||||||||
print(answer) | ||||||||||||||
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. Хороший нейминг. В целом код написан акуратно. |
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.
Есть 2 пожелания: