Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- def write_history(a, b, c, result):
- history = {'Number A': a, 'Number B': b, 'Operation': c, 'Result': result}
- with open('history.json', 'at') as file:
- json.dump(history, file, indent= " ")
- # file = open('history_2.txt', mode='at')
- # lines = [str(a), ' ', str(c), ' ',str(b), ' = ', str(result), '\n', '-' * 15, '\n']
- # file.writelines(lines)
- # file.close()
- def print_result(result):
- print('-' * 5)
- print('Результат: ', result)
- def slojenie(a, b):
- result = a + b
- write_history(a, b, '+', result)
- print_result(result)
- def vichitanie(a, b):
- result = a - b
- write_history(a, b, '-', result)
- print_result(result)
- def umnojenie(a, b):
- result = a * b
- write_history(a, b, '*', result)
- print_result(result)
- def delenie(a, b):
- result = a / b
- write_history(a, b, '/', result)
- print_result(result)
- def stepen(a, b):
- result = a ** b
- write_history(a, b, '**', result)
- print_result(result)
- while True:
- vibor = input("""Что хочешь сделать?\t
- Calculator - 'k'\t
- Help - 'i'\t
- history_2 - 'h'\t
- Exit - 'e'\t""")
- if vibor == 'k':
- action = input("Какую операцию хочешь совершить? (+ ,- ,* ,/ ,**)\n")
- if action == 'e': break
- elif action in ('+' ,'-' ,'*' ,'/' ,'**'):
- a = int(input("Введи число a: "))
- b = int(input("Введи число b: "))
- if action == "+":
- slojenie(a, b)
- input()
- print('-' * 5)
- elif action == "-":
- vichitanie(a, b)
- input()
- print('-' * 5)
- elif action == "*":
- umnojenie(a, b)
- input()
- print('-' * 5)
- elif action == "/" and b != 0:
- delenie(a, b)
- input()
- print('-' * 5)
- elif action == "/" and b == 0:
- print("На ноль делить нельзя.")
- input()
- print('-' * 5)
- elif action == "**":
- stepen(a, b)
- input()
- print('-' * 5)
- elif vibor == 'i':
- print(' Calculator v 1.1 \n Аффтар - Влад С. Вы можете отблагодарить разработчика обедом в маке :)')
- input()
- elif vibor == 'h':
- print('-' * 60)
- with open('history.json', 'rt') as file:
- history = json.load(file)
- print(history)
- # file = open('history_2.txt', mode='rt')
- # text = file.read()
- # print(text)
- # file.close()
- input()
- elif vibor == 'e': break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement