Finalise Ass 1

This commit is contained in:
Cal Wing 2025-02-27 22:09:11 +10:00
parent 4a47f58935
commit 136f1a6981

32
a1.py
View File

@ -214,7 +214,7 @@ def main():
print(HELP_MESSAGE) print(HELP_MESSAGE)
# Quit # Quit
if cmd[0] == "s": if cmd[0] == "q":
while True: while True:
cmd = input("Are you sure (y/n): ").lower() cmd = input("Are you sure (y/n): ").lower()
if cmd in ['y', 'n']: if cmd in ['y', 'n']:
@ -233,21 +233,33 @@ def main():
elif cmd[0] == "p": elif cmd[0] == "p":
if data is None: if data is None:
print("Please load data before using this command") print("Please load data before using this command")
continue
cmd = cmd.split() cmds = cmd.split()
if len(cmd) != 4: if len(cmds) != 4:
print("Please enter the correct number of arguments") print("Please enter the correct number of arguments")
continue continue
print_table(*cmd[1:], *data) # This makes ints & floats
foo = ()
for c in cmds:
if "." in str(c):
foo += float(c),
elif c.isnumeric():
foo += int(c),
else:
foo += c,
print_table(*foo[1:], *data)
# Make Graph # Make Graph
elif cmd[0] == "s": elif cmd[0] == "s":
if data is None: if data is None:
print("Please load data before using this command") print("Please load data before using this command")
continue
print("Simulating water heights...") print("Simulating water heights...")
heights = calc_heights_water_out(*data[0:5]) heights, _ = calc_heights_water_out(*data[0:5])
plot_water_height(heights, data[4]) plot_water_height(heights, data[4])
@ -257,6 +269,8 @@ def main():
##### End of Assisgnment #####
# See if I get what the task sheet wants # See if I get what the task sheet wants
# [NOTE] It seems I am witing my own test suite :/ that wasn't the initention lol # [NOTE] It seems I am witing my own test suite :/ that wasn't the initention lol
# Tests do equal what I get when i test it in the shell # Tests do equal what I get when i test it in the shell
@ -284,11 +298,15 @@ def sheet_tasks():
print("\nTask 9") print("\nTask 9")
global input global input # This is some magic I wrote a while ago to be an automatic input func
input = auto_input([ input = auto_input([
"h", "s", "q", "n", "h", "s", "q", "n",
"r", "test", "test_data.txt", "r", "test", "test_data.txt",
"p 280 20 6", "s", "p 280 20 6",
"r", "test", "test_data_2.txt",
's',
"q", "y" "q", "y"
]) ])
main() main()