final

parent c8b70977
......@@ -49,3 +49,60 @@
2020-12-24 12:35:56.157801 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 12:35:56.158796 : + : (3.2, 5.4, 1.0, 6) = 15.6
2020-12-24 13:08:11.592307 : + : (3.0, 4.0) = 7.0
2020-12-24 13:24:43.055152 : + : (1.0, 5.0, 8.0, 2.6) = 16.6
2020-12-24 13:25:06.881371 : * : (4.0, 0.5, 7.0, 8.12) = 113.68
2020-12-24 13:28:50.739547 : - : (2, 10.34) = -8.34
2020-12-24 13:28:50.740545 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:28:50.741573 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:28:50.744532 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 13:28:50.745532 : + : (3.2, 5.4, 1.0, 6) = 15.6
2020-12-24 13:30:44.266659 : - : (2, 10.34) = -8.34
2020-12-24 13:30:44.267654 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:30:44.268652 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:40:42.439985 : ^ : (5.0, 3.0) = 125.0
2020-12-24 13:52:28.571393 : - : (2, 10.34) = -8.34
2020-12-24 13:52:28.571393 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:52:28.572393 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:55:41.445078 : - : (2, 10.34) = -8.34
2020-12-24 13:55:41.446076 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:55:41.449111 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:56:15.861004 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:06:36.751973 : - : (2, 10.34) = -8.34
2020-12-24 14:06:36.752938 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:06:36.754965 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:07:04.374024 : - : (2, 10.34) = -8.34
2020-12-24 14:07:04.375022 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:07:04.376019 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:17:03.490601 : - : (2, 10.34) = -8.34
2020-12-24 14:17:03.491599 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:17:03.492597 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:17:20.245140 : - : (2, 10.34) = -8.34
2020-12-24 14:17:20.247205 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:17:20.248132 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:22:57.873281 : - : (2, 10.34) = -8.34
2020-12-24 14:22:57.874282 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:22:57.877240 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:36:04.816856 : - : (2, 10.34) = -8.34
2020-12-24 14:36:04.816856 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:36:04.820849 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:38:46.424016 : - : (2, 10.34) = -8.34
2020-12-24 14:38:46.424016 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:38:46.428009 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:40:48.845155 : - : (2, 10.34) = -8.34
2020-12-24 14:40:48.849180 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:40:48.849180 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:42:41.346920 : - : (2, 10.34) = -8.34
2020-12-24 14:42:41.346920 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:42:41.350908 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:18.246659 : - : (2, 10.34) = -8.34
2020-12-24 14:43:18.246659 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:43:18.266632 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:18.270628 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:43:18.270628 : * : (5, 3) = 15.0
2020-12-24 14:43:44.909308 : ^ : (5.0, 3.0) = 125.0
2020-12-24 14:43:56.104507 : - : (2, 10.34) = -8.34
2020-12-24 14:43:56.108501 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:43:56.108501 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:56.112465 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:43:56.112465 : ^ : (5, 3) = 125.0
2020-12-24 14:43:56.112465 : + : (3.2, 5.4, 1.0, 6) = 15.6
......@@ -34,6 +34,10 @@ def print_results(*args, action=None, result=None):
def write_log(*args, action=None, result=None, file='calc-history.log.txt'):
from datetime import datetime
try:
f = open(file, mode='a', errors='ignore')
f.write(f"{datetime.now()} : {action} : {args} = {result} \n")
f.close()
except:
print("Невозможно открыть или создать файл")
\ No newline at end of file
......@@ -40,6 +40,7 @@ def convert_precision(prec):
>>> convert_precision('s')
None
'''
try:
prec = str(prec)
for i in prec:
if i == 'e':
......@@ -48,6 +49,8 @@ def convert_precision(prec):
if i == ".":
x = prec.split('.')
return int(len(x[1]))
except ValueError:
print("Неверно указана точность, проверьте данные")
def user_input():
......@@ -70,7 +73,7 @@ def user_input():
if len(args) <= 1:
return
print("Введите один из знаков действия: +, -, *, / ")
print("Введите один из знаков действия: +, -, *, /, ^ ")
action = input("action: ")
try:
......@@ -121,6 +124,11 @@ def calculate(*args, action=None, **kwargs):
for n in args[1:(len(list(args)))]:
result /= n
if action == '^':
result = args[0]
for n in args[1:len(args)]:
result = result ** n
if type(result) is not output_type:
result = output_type(result)
......
......@@ -5,12 +5,10 @@ if __name__=="__main__":
load_params()
class TestCalculator(unittest.TestCase):
def test_summ(self):
self.assertEqual(
(calculate(*(3.2, 5.4, 1.0, 6), action="+", **PARAMS)), 15.6)
self.assertEqual((calculate(*(3.2, 5.4, 1.0, 6), action="+", **PARAMS)), 15.6)
def test_diff_pos(self):
self.assertEqual(
(calculate(*(8, 2.3, 0, 4.55), action="-", **PARAMS)), 1.15)
self.assertEqual((calculate(*(8, 2.3, 0, 4.55), action="-", **PARAMS)), 1.15)
def test_diff_neg(self):
self.assertEqual((calculate(*(2, 10.34), action="-", **PARAMS)), -8.34)
......@@ -18,17 +16,17 @@ if __name__=="__main__":
def test_mult(self):
self.assertEqual((calculate(*(3.2, 5.6, 1), action="*", **PARAMS)), 17.92)
def test_power(self):
self.assertEqual((calculate(*(5, 3), action="^", **PARAMS)), 125.0)
def test_div(self):
self.assertEqual(
(calculate(*(25, 5.0, 2.5), action="/", **PARAMS)), 2.0)
self.assertEqual((calculate(*(25, 5.0, 2.5), action="/", **PARAMS)), 2.0)
def test_precision(self):
self.assertEqual(convert_precision(0.0000001), 7)
self.assertEqual(convert_precision(0.001), 3)
def test_error(self):
with self.assertRaises(Exception):
calculate(*(5, 0), action="/", **PARAMS)
calculate(*('yes', 5), action="+", **PARAMS)
self.assertEqual(calculate(*(5, 0), action="/", **PARAMS),'Деление невозможно')
unittest.main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment