Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sem3-ivt19-task1-1-mozgovoy
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
Мозговой Никита Александрович
sem3-ivt19-task1-1-mozgovoy
Commits
75a4d38c
Commit
75a4d38c
authored
Nov 12, 2020
by
Мозговой Никита Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lr6
parent
222df306
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
8 deletions
+59
-8
calcprint.cpython-38.pyc
__pycache__/calcprint.cpython-38.pyc
+0
-0
calcprint.py
calcprint.py
+43
-0
calculate.py
calculate.py
+16
-8
No files found.
__pycache__/calcprint.cpython-38.pyc
0 → 100644
View file @
75a4d38c
File added
calcprint.py
0 → 100644
View file @
75a4d38c
def
print_results
(
*
args
,
action
=
None
,
result
=
None
):
"""
Вывод в табличном виде результатов вычислений
Функция принимает переменное число значений, которые нужно вывести в табличном виде.
последний аргумент в упакованном кортеже - результат вычислений,
предпоследний - действие, которое выполнилось,остальные — аргументы, с которыми это действие выполнилось.
"""
operands
=
args
[:
len
(
args
)]
print
(
'inp_args in pretty mode'
,
operands
,
action
,
result
)
from
string
import
ascii_lowercase
# print(ascii_lowercase)
def
argsPrint
(
operands
):
lst
=
[]
for
i
in
operands
:
lst
.
append
(
f
"| {i} |"
)
return
lst
def
actionPrint
(
operands
,
action
):
lst
=
[]
for
i
in
range
(
operands
[
0
],
operands
[
-
1
]):
lst
.
append
(
f
" {i} {action} "
)
lst
.
append
(
f
" {operands[-1]} "
)
return
lst
arg_list
=
str
((
argsPrint
(
operands
)))
action_list
=
str
(
actionPrint
(
operands
,
action
))
st
=
f
"| {arg_list} | {action_list} = {result} |"
print
(
'-'
*
len
(
st
))
print
(
st
)
print
(
'-'
*
len
(
st
))
# Пример вывода большого количества аргументов
# inp = 100, 200, 300, action = +
#
# ************************************
# * A, B, C * A + B + C *
# ************************************
# * 100, 200, 300 * 13579 *
# ************************************
calculate.py
View file @
75a4d38c
from
calcprint
import
print_results
PARAMS
=
{
'precision'
:
0.00001
,
'output_type'
:
float
,
'possible_types'
:
(
int
,
float
)}
...
...
@@ -19,31 +20,31 @@ def calculate(*args, **kwargs):
output_type
=
kwargs
[
'output_type'
]
print
(
precision
)
if
args
[
args
[
-
1
]
]
==
'+'
:
result_sum
=
sum
(
args
[
0
:
args
[
-
1
]
])
if
args
[
-
1
]
==
'+'
:
result_sum
=
sum
(
args
[
0
:
-
1
])
if
type
(
result_sum
)
is
not
output_type
:
result_sum
=
output_type
(
result_sum
)
return
result_sum
if
args
[
args
[
-
1
]
]
==
'-'
:
if
args
[
-
1
]
==
'-'
:
result_diff
=
0
for
n
in
args
[
0
:
args
[
-
1
]
]:
for
n
in
args
[
0
:
-
1
]:
result_diff
-=
n
if
type
(
result_diff
)
is
not
output_type
:
result_sum
=
output_type
(
result_diff
)
return
result_diff
if
args
[
args
[
-
1
]
]
==
'*'
:
if
args
[
-
1
]
==
'*'
:
result_mult
=
1
for
n
in
args
[
0
:
args
[
-
1
]
]:
for
n
in
args
[
0
:
-
1
]:
result_mult
*=
n
if
type
(
result_mult
)
is
not
output_type
:
result_mult
=
output_type
(
result_mult
)
return
round
(
result_mult
,
precision
)
if
args
[
args
[
-
1
]
]
==
'/'
:
if
args
[
-
1
]
==
'/'
:
result_division
=
args
[
0
]
for
n
in
args
[
1
:
args
[
-
1
]
]:
for
n
in
args
[
1
:
-
1
]:
result_division
/=
n
if
type
(
result_division
)
is
not
output_type
:
result_division
=
output_type
(
result_division
)
...
...
@@ -63,3 +64,10 @@ def test_packed_calc_sum():
assert
type
(
calculate
(
*
inp1
,
action
,
**
PARAMS
))
is
type
(
45.0
),
'Type of sum is incorrect'
if
__name__
==
"__main__"
:
# print(calculate(*list(range(1, 10)), "+", **PARAMS), '\n') # 1 + 2 + 3 + .. + 9
# print(calculate(*list(range(1, 10)), "-", **PARAMS), '\n')
# print(calculate(*list(range(1, 5)), "/", **PARAMS), '\n')
# print(calculate(*[1.0001, 2.2345], "*", **PARAMS), '\n') # 2.23472345
print_results
(
*
list
(
range
(
1
,
10
)),
action
=
"+"
,
result
=
calculate
(
*
list
(
range
(
1
,
10
)),
"+"
,
**
PARAMS
))
\ 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