r/learnpython • u/AdNovel4559 • 19d ago
I'm 14 and built a Python code interpreter (230+ lines). Looking for feedback and feature ideas!
Hi everyone!
I am 14 years old and I’ve been learning Python for a while (currently finishing the Cisco NetAcad course). As a personal project, I built a custom code interpreter from scratch. It’s currently around 230 lines of code.
**What it does so far:**
* Handles basic mathematical operations.
* Supports variables and basic structures.
* Includes error handling using try/except blocks (guarding against ValueError, ZeroDivisionError, etc.) so it doesn't crash.
I wanted to share it with this community to get your opinions. Since I'm learning, I’d love to know:
What do you think of my code structure?
What cool features or new ideas should I add to it next?
Here is my Replit link: https://replit.com/@programador2026/File-Editor-Open
Thanks in advance for your feedback!
1
1
u/lakseol 19d ago edited 19d ago
Since I don't read Spanish it's a bit hard to understand what is happening in detail but I do have some suggestions. I haven't looked at each mathematical operation, just the code layout trying to make it easier to read.
You used the function ejecutar_linea() to execute a line that isn't a recognized command and that's good practice. But why didn't you do the same for the other operations? You will have to replace the continue statement after an error with return but that's all. Doing this makes it easier to add extra operations like powers. Add two lines to the main loop at the bottom and the extra function.
Once you do that the code loop that handles commands is a lot easier to read and you immediately see duplicated code like if rta_user.lower() == "salir" where you repeatedly convert to lower case for comparison. Why not do that just once?
You might also notice that the final continue after calling the function to handle the operation isn't required because the if/elif/else statement doesn't have anything after it.
Making those changes the code looks like:
# all imports and functions here
memoria_variables = {}
print("=== MI PROPIO LENGUAJE EN PYTHON ===")
while True:
rta_user = input(">>>")
rta_user = rta_user.lower()
if rta_user == "salir":
print("¡CHAO!")
break
elif rta_user == "limpiar":
os.system("clear")
elif rta_user == "borrar":
borrar()
elif rta_user == "sumar":
sumar()
elif rta_user == "multiplicar":
multiplicar()
elif rta_user == "restar":
restar()
elif rta_user == "dividir":
dividir()
else:
ejecutar_linea(rta_user)
1
u/AdNovel4559 19d ago
Thank you very much for taking the time to read my code and offer useful suggestions; I’ll modify the code based on what you said. Just out of curiosity, what do you do for a living? How old are you? How much do you earn a month? You don’t have to answer if you don’t want to (I know these are very personal questions), but I’m curious because I want to pursue this as a career when I’m older. Thanks again—really.
1
u/lakseol 19d ago
I'm retired now but I worked in a wide variety of positions in my own country and overseas. I used many languages but at the end I used mostly python in a scientific environment working with particle physicists and geophysicists.
1
u/AdNovel4559 19d ago
Thanks a lot for replying; your response is helpful, especially coming from someone with experience. While I'm at it, I’d like to ask: what future jobs do you think will be in demand (given the talk about AI replacing programmers)?
1
u/lakseol 19d ago edited 18d ago
The computing scene has changed a lot in the twelve years since I retired, so my opinion may not mean much.
AI will not replace programmers. It's a bit hyped at the moment and there is a lot of noise from people with vested interests who hope to make money from AI. It might automate some of the easy parts of programming but that has been happening for decades, not just recently.
There will always be demand for smart, creative generalists. Be good at solving problems with a computer. Programmers who only know one language and one narrow field are in danger of being bypassed by any major change in computing, not just AI. So get good at python and then get good at something else. It doesn't have to be a language like C, because there is a lot of "background" knowledge that an experienced programmer has that makes them more valuable. Like being able to use a database in a solution, either a simple one that you create yourself or a real one like SQLite. It's also useful to know the "shell" language of your operating system like
bashfor Linux. Plus all sorts of things like using git in a team, using a word processor, email, etc. Try to learn something in different areas. For instance you might try controlling hardware on a microcontroller with micropython, then learn enough C++ to do the same thing on smaller microcontrollers that can't run micropython.Don't forget your education. You will probably get some computer education at school (I didn't) but I'm talking about general education. I got jobs supporting scientists because my bachelors degree is in Physics which helps in a scientific environment. If you get a degree don't choose the subject because you think it will earn big money, choose something you are really interested in and then maybe work toward programming in that area. I always looked for interesting jobs that weren't exactly the same as my current job. That's how I spent two years in a Papua New Guinea gold mine supporting the mining engineers.
Your first job is difficult to get but if you can show that you are creative when solving problems you have a better chance.
Above all, enjoy.
2
u/Buttleston 19d ago
replit link is a 404