Initial commit

This commit is contained in:
Ryan Whytsell 2023-12-23 15:47:28 -05:00
commit 3ae519a6bd
No known key found for this signature in database
GPG Key ID: BD7B18309414DE50
2 changed files with 96 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
./.idea

95
main.py Normal file
View File

@ -0,0 +1,95 @@
import ast
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
VERSION = "0.0.0"
sContinue = True
state = []
def show_help():
print("vector [5,6,7...] - set the current dataset to the given vector")
print("stdd - get the standard deviation of the current dataset")
print("mean - get the mean of the current dataset")
print("median - get the median of the current dataset")
print("mode - get the mode of the current dataset")
print("var - get the variance of the current dataset")
print("print - prints the current dataset")
print("clear - clears the current dataset")
print("clr - clears the screen")
def get_mean():
"""
Get the mean value of the state vector.
:return: The average value of the state vector.
"""
global state
mean = sum(state) / len(state)
return mean
def get_median():
"""
This function calculates the median of the state vector.
The implementation uses the algorithm based on sorting.
:return: The median value of the sorted `state` list.
"""
global state
state.sort()
n = len(state)
median = 0
if n % 2 == 0:
median = (state[n // 2 - 1] + state[n // 2]) / 2
else:
median = state[n // 2]
return median
def start_shell():
global state
state = []
print(f'Welcome to math-shell v{VERSION}')
handle_input()
def handle_input():
global state
value = []
print('>>>', end=' ')
i = input()
should_split = i.__contains__(' ')
if should_split:
command, value = i.split(sep=' ', maxsplit=1)
value = ast.literal_eval(value)
else:
command = i
match command.lower():
case 'vector':
state = value
print(f"Set state to: {value}")
case 'mean':
print(get_mean())
case 'print':
if state is not None:
print(f"{state}")
else:
print("No state")
case 'exit':
return False
case other:
show_help()
return True
if __name__ == '__main__':
start_shell()
while sContinue:
sContinue = handle_input()