Big Idea 3
AP CSP’s Big Idea 3 is centered around data and how it can be represented and manipulated. This includes variables, data abstraction, strings, boolean expressions, conditionals, iteration, lists, developing algorithms, and mathematical expressions.
3.1 Variables and Assignments
Understanding variables and assignments was a strong base in my experience learning how to code. Variables can store data, which can then be referenced and stored throughout the program.
in my gemini.py, I use variables to create and store messages dynamically based on user input. For example, when processing a message, the variable ai_message holds the newly created message object:
def update_history(self, role: str, message: str):
ai_message = AIMessage(
message=message,
author=role,
category="response" if role == "assistant" else "user"
)
ai_message.create()
return ai_message.id
Here, the variable ai_message stores an instance of the AIMessage class, which includes the message text, author, and category. After calling ai_message.create(), the message is saved, and its unique ID is returned. This demonstrates how variables can dynamically manage user input and store data efficiently, making the system responsive and organized.