diff --git a/Reference Scripts/Number Sorting.py b/Reference Scripts/Number Sorting.py new file mode 100644 index 0000000..e236004 --- /dev/null +++ b/Reference Scripts/Number Sorting.py @@ -0,0 +1,49 @@ +#!~/.pyenv/versions/3.11.6/bin/python + +# Copyright (c) 2024 Cutieguwu | Olivia Brooks +# +# -*- coding:utf-8 -*- +# @Title: Numerical bubble sorter. +# @Author: Cutieguwu | Olivia Brooks +# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca +# @Description: Simple Least to Greatest bubble sorter. +# +# @Script: 1.py +# @Date Created: 20 Mar, 2024 +# @Last Modified: 21 Mar, 2024 +# @Last Modified by: Cutieguwu | Olivia Brooks + +from os import path + +with open(path.dirname(__file__) + "/sortfiles/sort1.txt", "rt") as f: + sortData = f.readlines() + +print(f"Fetched from ./sortfiles/sort1.txt\n{sortData}") +print("Cleaning up...") + +for i in range(0, len(sortData)): + sortData[i] = int("".join(c for c in sortData[i] if c.isdigit())) + +def is_sorted(): + IS_SORTED = [] + for i in range(0, len(sortData) - 1): + if sortData[i] > sortData[i + 1]: + IS_SORTED.append(False) + else: + IS_SORTED.append(True) + + if False in IS_SORTED: + IS_SORTED_FLAG = False + else: + IS_SORTED_FLAG = True + return IS_SORTED_FLAG + +while is_sorted() is False: + for i in range(0, len(sortData) - 1): + if sortData[i] > sortData[i + 1]: + sortTemp = sortData[i + 1] + sortData[i + 1] = sortData[i] + sortData[i] = sortTemp + +print("Finished.") +print(f"Cleaned data:\n{sortData}") \ No newline at end of file diff --git a/Reference Scripts/Parallel Lists using common indexing for association.py b/Reference Scripts/Parallel Lists using common indexing for association.py new file mode 100644 index 0000000..954959a --- /dev/null +++ b/Reference Scripts/Parallel Lists using common indexing for association.py @@ -0,0 +1,84 @@ +#!~/.pyenv/versions/3.11.6/bin/python + +# Copyright (c) 2024 Cutieguwu | Olivia Brooks +# +# -*- coding:utf-8 -*- +# @Title: Story Translator. +# @Author: Cutieguwu | Olivia Brooks +# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca +# @Description: A simple story translator. +# +# @Script: main_school.py, forked from main.py +# @Date Created: 23 Mar, 2024 +# @Last Modified: 11 April, 2024 +# @Last Modified by: Cutieguwu | Olivia Brooks + +with open("story.txt", "r") as f: # Load story from file. + story = f.read() + +def dictionaryLoad(directory): + with open(directory, "r") as f: + dictionary = f.readlines() + + return dictionary + +dictionaryEnglish = dictionaryLoad("English.txt") +dictionaryFrench = dictionaryLoad("French.txt") + +def dictionaryClean(dictionary): + for i in range(0, len(dictionary)): + dictionary[i] = "".join(c for c in dictionary[i] if c != "\n") + + return dictionary + +dictionaryEnglish = dictionaryClean(dictionaryEnglish) +dictionaryFrench = dictionaryClean(dictionaryFrench) + +def translate(string): + """ + Transates a given string. + Returns a rough translation. + """ + + # Begin translation. + word = "" + wordNew = "" + storyTranslated = "" + + for c in story: + if c != " " and c != "." and c != "," and c != "\n": # Not end of word. + word = word + c + else: + print("- Found special character") + + if word.lower() in dictionaryFrench: # `word` is not empty or has a known translation; + # additionally fixes ". " and " " events. + + for i in range(0, len(dictionaryFrench)): # Parse the dictionary for the word's index. + + if word.lower() == dictionaryFrench[i]: # If the word is found, fetch its english translation. + + wordNew = dictionaryEnglish[i].lower() # Fetch the index for the corresponding word in English. + + if word[0].isupper(): # Adjust capitalization if needed. + wordReconstructed = wordNew[0].upper() + + for character in wordNew: + if wordNew.index(character) != 0: + wordReconstructed = wordReconstructed + character + else: + pass + + wordNew = wordReconstructed + + storyTranslated = storyTranslated + wordNew + c # Place the word and its proceeding special character in the story. + + else: # Finish building the search string and place it in the story since it's complete and cannot be translated. + word = word + c + storyTranslated = storyTranslated + word + + word = "" + + return storyTranslated + +print(translate(story)) \ No newline at end of file diff --git a/Reference Scripts/Singluar List for Frequencies.py b/Reference Scripts/Singluar List for Frequencies.py new file mode 100644 index 0000000..b68e9b8 --- /dev/null +++ b/Reference Scripts/Singluar List for Frequencies.py @@ -0,0 +1,62 @@ +#!~/.pyenv/versions/3.11.6/bin/python + +# Copyright (c) 2024 Cutieguwu | Olivia Brooks +# +# -*- coding:utf-8 -*- +# @Title: Coin Flipper. +# @Author: Cutieguwu | Olivia Brooks +# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca +# @Description: Runs a given number of trials of 5 coin flips and reports the total groupings of tails. +# +# @Script: 8.py +# @Date Created: 06 March, 2024 +# @Last Modified: 07 March, 2024 +# @Last Modified by: Cutieguwu | Olivia Brooks + +from random import randint + +trials = "" +while trials.isnumeric() == False: # Ensure that user enters a number value to iterate. + trials = input("Enter a number of trials to run: ") + +trials = int(trials) + +tails = 0 # Tails in 5 throws +tailsGroups = [0, 0, 0, 0, 0, 0] # Index indicates number of tails present, value indicates frequency of the group. + + +def make_plural(x=int(), msg=str()): + """ + Appends "s" to msg if the value given isn't 1. + Returns the modified msg. + """ + + if x != 1: + msg = msg + "s" + + return msg + +for x in range(trials): # Main run loop, runs for number of trials given. + msgTrial = "" + tails = 0 + + for i in range(5): # Run a trial; flip a "coin" five times. + flip = randint(1, 2) + msg = ", " + + if i == 0: + msg = "" + + if flip == 1: + msg = msg + "Heads" + else: + msg = msg + "Tails" + tails = tails + 1 # Record the number of tails for the trial. + + msgTrial = msgTrial + msg + + print(f"{msgTrial} You got {tails} tails.", end="") # Print all results of the trial at once. + tailsGroups[tails] = tailsGroups[tails] + 1 # Increment the appropriate tails. + +for i in range(len(tailsGroups)): # Produce results with proper grammar. + print(make_plural(tailsGroups[i], make_plural(i, f"Rolled {i} tail") + f" in {tailsGroups[i]} trial") + ".") # Produce and print the final report, making "tail" plural if needed. \ No newline at end of file