Welcome to the database of students' Python programs!

This database of Python code contains some programs from past students, as well as some of the teacher’s own programs!

Try a program out!

terminal = true packages = ["colorama"] [[fetch]] from = "https://pleyouth.org/wp-content/themes/astra-child/" files = ["programs.txt", "wait_until_input.txt", "reset.txt"] import asyncio import random import colorama user_input_file = open("user_input.txt", "w") user_input_file.close() extra_indent = "" def addLine(program, line, indented = False, addLine = True): indent = "" newLine = "" if indented: indent = " " if addLine: newLine = "\n" program += (extra_indent+indent + line + newLine) return program def submit_user_input(*args, **kwargs): user_input_file = open("user_input.txt", "w") user_input_file.write(Element("py-input").element.value) user_input_file.close() Element("py-input").clear() def reset_input(): user_input_file = open("user_input.txt", "w") user_input_file.write("") user_input_file.close() Element("py-input").clear() class Program_manager(): def __init__(self): self.program_list = [] def replace_inputs(self, old_program): global extra_indent isInt = False new_program = "" message = "" new_program = addLine(new_program, "async def runProgram():") new_program = addLine(new_program, "try:", True) extra_indent = " " for line in old_program.splitlines(): if "input(" in line: isInt = False if "int(" in line: isInt = True indent = "" for char in line: if char == " ": indent += char else: break equals = int(line.index("=")) variable = line[0:equals].strip() left_parenthesis = int(line.index("input("))+5 right_parenthesis = int(line.index(")")) message = line[left_parenthesis+1:right_parenthesis] print_message = indent+"print(" + message + ")" if not isInt: retrieve_input = variable + " = user_input" elif isInt: retrieve_input = variable + " = int(user_input)" new_program = addLine(new_program,print_message, True) wait_until_input_file = open("wait_until_input.txt", "r") for line in wait_until_input_file: new_program = addLine(new_program, indent+line, False, False) new_program = addLine(new_program, indent+retrieve_input, True) reset_file = open("reset.txt", "r") for line in reset_file: new_program = addLine(new_program, indent+line, False, False) reset_file.close() else: new_program = addLine(new_program, line, True) extra_indent = "" new_program = addLine(new_program, "\n except:\n Element(\"error_msg\").write(\"Sorry, the program ran into an error\")\n reset_input()", True) new_program = addLine(new_program, "\nasyncio.ensure_future(runProgram())") return new_program def get_program_list(self): file = open("programs.txt", "r") programs = file.read() self.program_list = programs.split("\n-----------------------------\n") file.close() def init_program(self,program_id, program_code, program_name, student_name, student_age): program_template = Element("program_template") program_list = Element("program_list") html_text = "\"" + program_name + "\" by " + student_name + ", " + student_age program_html = program_template.clone(program_id) program_html.element.setAttribute("value", html_text) program_list.element.appendChild(program_html.element) old_code = program_code program_code = self.replace_inputs(program_code) def run_program(evt= None): Element("terminal").clear() reset_input() Element("error_msg").clear() Element("terminal_header").write("Now running \"" + program_name + "\" by " + student_name + "...") Element("code_display").write(old_code) exec(program_code) reset_input() program_html.element.onclick = run_program def list_out_programs(self): for item_num in range(0,len(self.program_list)-1): program_profile = self.program_list[item_num].split("\n~~~~~~~~\n") program_name = program_profile[2].capitalize() student_age = program_profile[1] student_name = program_profile[0].capitalize() program_id = str(item_num) program_code = program_profile[3] self.init_program(program_id, program_code, program_name, student_name, student_age) program_manager = Program_manager() program_manager.get_program_list() program_manager.list_out_programs()

Interact with the program here:
What the current code running looks like: