Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pr Lab 1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Каменцев Георгий Константинович
Pr Lab 1
Commits
5f668e8f
Commit
5f668e8f
authored
Oct 01, 2024
by
Каменцев Георгий Константинович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Основной код калькулятора
parent
714de535
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
main.py
Калькулятор/main.py
+52
-0
No files found.
Калькулятор/main.py
0 → 100644
View file @
5f668e8f
"""this program calculates operations based on the user input"""
def
calculate
(
val1
,
val2
,
operation
):
"""
main calculating function
expects first variable, second variable, and operation in order
supports only +,-,*,/
"""
# checking the operation type
match
operation
:
case
'+'
:
return
val1
+
val2
case
'-'
:
return
val1
-
val2
case
'*'
:
return
val1
*
val2
case
'/'
:
return
val1
/
val2
case
_
:
# if user inputs unsuuported operation throw an error
return
'Invalid Operation'
# tests
def
test_calculate_summation
(
val1
,
val2
):
assert
calculate
(
val1
,
val2
,
'+'
)
==
val1
+
val2
,
'addition'
def
test_calculate_subscription
(
val1
,
val2
):
assert
calculate
(
val1
,
val2
,
'-'
)
==
val1
-
val2
,
'subtraction'
def
test_calculate_multiplication
(
val1
,
val2
):
assert
calculate
(
val1
,
val2
,
'*'
)
==
val1
*
val2
,
'multiplication'
def
test_calculate_division
(
val1
,
val2
):
assert
calculate
(
val1
,
val2
,
'/'
)
==
val1
/
val2
,
'division'
# thirst variable
a
=
int
(
input
())
# second variable
b
=
int
(
input
())
# testing
test_calculate_summation
(
a
,
b
)
test_calculate_subscription
(
a
,
b
)
test_calculate_multiplication
(
a
,
b
)
test_calculate_division
(
a
,
b
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment