Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
266fb2f
Create calculator.py
VovaGrig Sep 11, 2023
a735b21
Create main and plus functions
Sep 11, 2023
6499381
Added comments to main and plus functions
Sep 11, 2023
8becf4c
Upgraded main function, deleted plus function
Sep 11, 2023
91b453f
Added multiplication in calculator
e-chevokina Sep 11, 2023
d07d5f2
Added multiplication in calculator
e-chevokina Sep 11, 2023
f1b4b30
Added plus function
duckweedGuard Sep 11, 2023
ff3c40c
Added division
asyapetukhova Sep 11, 2023
11074e7
Create folder HW2_Grigoriants, moved calculator.py there
Sep 12, 2023
07a6dcb
Delete useless duplicated calculator.py
Sep 12, 2023
1f6c822
Update calculator.py to look nice
Sep 12, 2023
f1c15c8
Merge branch 'HW2_Grigoriants' of github.com:duckweedGuard/HW2_Git_an…
duckweedGuard Sep 12, 2023
f08c02a
Add sum function
duckweedGuard Sep 12, 2023
cf66dc5
Add multiplication function in calculator.py
e-chevokina Sep 12, 2023
405080f
Merge branch 'HW2_Grigoriants' of https://github.com/e-chevokina/HW2_…
e-chevokina Sep 12, 2023
151d7bf
Merge branch 'HW2_Grigoriants' of github.com:asyapetukhova/HW2_Git_an…
asyapetukhova Sep 12, 2023
a9aaa62
Update calculator.py to look nice
Sep 12, 2023
037bb9f
Merge branch 'HW2_Grigoriants' of github.com:VovaGrig/HW2_Git_and_pyt…
Sep 12, 2023
b41e261
Merge pull request #6 from e-chevokina/HW2_Grigoriants
VovaGrig Sep 12, 2023
dfb9c82
Merge branch 'HW2_Grigoriants' into HW2_Grigoriants
VovaGrig Sep 12, 2023
72090cf
Merge pull request #5 from duckweedGuard/HW2_Grigoriants
VovaGrig Sep 12, 2023
bcdecee
Merge branch 'HW2_Grigoriants' into HW2_Grigoriants
VovaGrig Sep 12, 2023
693f0d0
Merge pull request #8 from asyapetukhova/HW2_Grigoriants
VovaGrig Sep 12, 2023
a4016a0
Move README.md to HW2_Grigoriants
Sep 12, 2023
48ac7a9
Merge branch 'HW2_Grigoriants' of github.com:VovaGrig/HW2_Git_and_pyt…
Sep 12, 2023
97d4619
Update README.md
VovaGrig Sep 12, 2023
fc9f004
Fix main function
VovaGrig Sep 12, 2023
db1237c
Update division function in calculator.py for true mathematicians
VovaGrig Sep 12, 2023
45a4ffe
Add function minus
MariaLuk Sep 12, 2023
573a274
Merge pull request #9 from MariaLuk/HW2_Grigoriants
VovaGrig Sep 12, 2023
8499af9
Update README.md
VovaGrig Sep 12, 2023
c6ff335
Add README.md with hometask to the root directory
VovaGrig Sep 13, 2023
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
13 changes: 13 additions & 0 deletions HW2_Grigoriants/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# HW2_Git_and_python by Git Dream Team
Наша команда обеспечила Github комьюнити новейшим вычислительным механизмом. С её помощью школьная арифметика больше не создаст ни для кого проблем! Программа принимает на вход строку с некоторым математическим выражением и выводит число - результат вычисления этого выражения.

Copy link

Choose a reason for hiding this comment

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

Есть 2 пожелания:

  • пишите README на английском языке, чтобы в будущем ваш код могло использовать не только русско-говорящее сообщество. Лучше сразу привыкать;
  • полезно приводить примеры кода, потому что по вашему описанию можно подать математическое выражение 1+2 и тогда ничего не сработает.

# Состав команды:
* Виктория Орлова
* Анастасия Петухова
* Мария Лукина
* Елизавета Чевокина
* Владимир Григорянц - наш ***тимлид***

Инсайд с нашего собрания:

![image](https://drive.google.com/uc?export=view&id=181Ll1FVtIYlqSVfIOlHKuLzf1bF7Y1V1)
32 changes: 32 additions & 0 deletions HW2_Grigoriants/calculator.py
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?"
Copy link

Choose a reason for hiding this comment

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

Когда вы проводите операции над числами, вы ожидаете, что на выходе получите другое число. Здесь же вернется строка. В таких ситуациях лучше останавливать программу и выбрасывать ошибку. Например:

Suggested change
return "Dude, for real?"
print('Dude, for real?', file=sys.stderr)
os.exit(1)

С модулями sys и os вы еще познакомитесь:)

else:
Copy link

Choose a reason for hiding this comment

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

else здесь не нужен

return num1 / num2

def plus(num1, num2): #sum of numbers
Copy link

Choose a reason for hiding this comment

The 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):
Copy link

Choose a reason for hiding this comment

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

Suggested change
def minus (num1, num2):
def minus(num1, num2):

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
Copy link

Choose a reason for hiding this comment

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

в целом рабочий вариант, но есть переиспользование кода, лучше было бы сделать так:

Suggested change
num1 = float(my_string.split()[0])
num2 = float(my_string.split()[2])
sign = my_string.split()[1]
num1, sign, num2 = my_string.split()
num1 = float(num1)
num2 = float(num2)

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
Copy link

Choose a reason for hiding this comment

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

Обратите внимание: по PEP8 после функции идет пропуск 2х строк.

answer = main()
print(answer)
Copy link

Choose a reason for hiding this comment

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

Хороший нейминг. В целом код написан акуратно.