One idea
A runnable tool is easier to trust when the work is inside functions, not floating at the top of the file.
Keep one file for reusable logic and one file for the command people run.
Why this matters
In hackathon repos, reviewers often open your code before they run it. If everything is one long script, it is hard to see what reads input, what processes data, and what writes output.
Functions give names to those steps. Modules let you reuse those functions later when you add JSON files, APIs, or tests.
Split the job
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Small module
Create a file named processor.py. This file holds logic you can import without running the whole tool.
# processor.py
def clean_text(text):
return text.strip().lower()
def make_label(record):
name = clean_text(record["name"])
city = clean_text(record["city"])
return f"{name} from {city}"
def build_output(records):
labels = []
for record in records:
labels.append(make_label(record))
return labelsRunnable script
Create a second file named run_tool.py. This is the file someone will run from the terminal.
The if block means the tool runs only when this file is executed directly. It will not run by accident when another file imports it.
# run_tool.py
from processor import build_output
def main():
sample_records = [
{"name": " Asha ", "city": " Pune "},
{"name": " Ravi ", "city": " Kochi "},
]
labels = build_output(sample_records)
for label in labels:
print(label)
if __name__ == "__main__":
main()Ask AI well
AI tools are useful for refactoring a long script into functions. Paste only the relevant code and ask for small functions with clear names.
Check that the AI did not change your data shape, hide errors, or move file reading into every function. Run the script after every change.
Refactor this Python script into small functions.
Keep the same input and output.
Put reusable logic in processor.py.
Put the runnable main() in run_tool.py.
Do not add new libraries.Common mistake
Do not call main() at the bottom of a module file that you plan to import. That can make code run twice or run at the wrong time.
Use the __name__ check in the script that is meant to be executed.
# Good
if __name__ == "__main__":
main()Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done