Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions HW2_Stepanova/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store/
23 changes: 23 additions & 0 deletions HW2_Stepanova/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# About calculator

A calculator is a program that performs basic arithmetic operations: addition, subtraction, multiplication and division. The calculator takes as input ( ) a string with some mathematical expression and prints a number - the result of calculating this expression.

# Requirements

Python 3.x (tested on Python 3.8 and above).

# Team

Shchekuteva Ekaterina, Revyakina Lilia, Loginova Olga, Stepanova Arina.

# Citation

;) If you use calculator in your work, please cite [https://github.com/arrstepa/HW2_Stepanova].

# Feedback and bug reports

If you have any troubles running calculator, please attach params.txt and calculator.log :)

# Screenshot of the team meeting

![](imgs/screenshot.jpg)
32 changes: 32 additions & 0 deletions HW2_Stepanova/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def multiple(a,b):
"Функция умножения двух чисел"
return a*b
Comment on lines +1 to +3

Choose a reason for hiding this comment

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

Suggested change
def multiple(a,b):
"Функция умножения двух чисел"
return a*b
def multiplication(a, b):
"Функция умножения двух чисел"
return a * b

Choose a reason for hiding this comment

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

На будущее - все описания и комментарии стоит писать на английском.


def substraction(a, b):

Choose a reason for hiding this comment

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

Однобуквенные переменные стоит оставить только для счетчиков. Хорошо бы подошло num1, num2, или что-то еще подобное.

"Функция вычитания b из a"
return a - b

def addition (a, b):
"Функция сложения двух чисел"
return a + b

def division (a, b):
"Функция деления a на b"
if b!= 0:
return a/b
else:
return "деление на 0!"
Comment on lines +13 to +18

Choose a reason for hiding this comment

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

Suggested change
def division (a, b):
"Функция деления a на b"
if b!= 0:
return a/b
else:
return "деление на 0!"
def division (a, b):
"Функция деления a на b"
if b != 0:
return a / b
else:
return "деление на 0!"

Choose a reason for hiding this comment

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

Здорово, что про проверку подумали. Про ошибки и работу с ними еще поговорим, но пока как базовое правило - в большинстве случаев функция должна возвращать возвращать один ожидаемый тип данных. Иногда - тот тип данных, который ей дали. Но функция, которая что-то считает, не должна отдавать строку просто так. Просто запомнить пока что!


def main():
exp=input("Введите выражение: ").split()
a,operation,b = float(exp[0]), exp[1], float(exp[2])

Choose a reason for hiding this comment

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

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

if operation == "+":
print(addition(a,b))
elif operation == "-":
print(substraction(a,b))
elif operation == "*":
print(multiple(a,b))
else:
print(division(a,b))
Comment on lines +20 to +30

Choose a reason for hiding this comment

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

Suggested change
def main():
exp=input("Введите выражение: ").split()
a,operation,b = float(exp[0]), exp[1], float(exp[2])
if operation == "+":
print(addition(a,b))
elif operation == "-":
print(substraction(a,b))
elif operation == "*":
print(multiple(a,b))
else:
print(division(a,b))
def main():
exp = input("Введите выражение: ").split()
a, operation, b = float(exp[0]), exp[1], float(exp[2])
if operation == "+":
print(addition(a, b))
elif operation == "-":
print(substraction(a, b))
elif operation == "*":
print(multiple(a, b))
else:
print(division(a, b))


main()
Binary file added HW2_Stepanova/imgs/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.