-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (38 loc) · 2.4 KB
/
Copy pathmain.py
File metadata and controls
51 lines (38 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from operations import OPERATIONS, operator_collection
from data import request_data_from_user, check_input_for_number
from colored import colored_input, colored_print, run_colored
RESTART_KEYWORD = "1"
clear_screen = lambda: os.system("cls")
def show_menu() -> None:
"""
This procedure will show the user a simple guide to explain the
purpose and expected input for the prober use
"""
colored_print(f"%tGreetings user,\n%nyou currently using my Simple Calculator program.\nThe current version of this instance is %i{PROGRAM_VERSION}%n")
colored_print(f"\n%nThis calculator is designed to calculate single operations only.\nYou can input two integer or float values called number 1 and 2")
colored_print(f"%nand an operator with witch the calculation will be made,\ncurrently there are the following operations to use: %i{operator_collection}%n.")
colored_print(f"\n%nPlease enter the following information in order to get\nthe desired outcome:")
def main():
program_active = True
clear_screen()
while program_active:
show_menu()
number_1 = request_data_from_user(prompt="Please enter the first number: ",
error_case=lambda x: f'%i"{x}"%e is not a valid input, please enter only %ifloat%e or %iinteger%e values!',
validation_func=check_input_for_number)
operator_func = request_data_from_user(prompt=f"Please enter you desired operator %i[{operator_collection}]: ",
error_case=lambda x: f'%i"{x}"%e is not a valid operator, please select out of thus valid ones: %i{operator_collection}',
validation_func=lambda x: OPERATIONS.get(x))
number_2 = request_data_from_user(prompt="Please enter the second number: ",
error_case=lambda x: f'%i"{x}"%e is not a valid input, please enter only %ifloat%e or %iinteger%e values!',
validation_func=check_input_for_number)
if not callable(operator_func):
raise TypeError(f"the action set for the current operator is not a callable: {operator_func}")
result = operator_func(number_1, number_2)
colored_print(f"%nYou result is %ui{result}")
user_input = colored_input(f'Start Another Calculation? %i("{RESTART_KEYWORD}": yes, Any: stop)')
program_active = user_input == RESTART_KEYWORD
clear_screen()
if __name__ == "__main__":
run_colored(main)