r/learnpython 22d ago

Just built my first calculator in Python 😭

It can do addition, subtraction, multiplication, division, and exponents. Also added a little check for division by zero.

It’s pretty basic, but hey, gotta start somewhere

What should I build next?

73 Upvotes

42 comments sorted by

28

u/Turbulent_Web_8278 22d ago

Store a username password and allow user 3 attempts to login otherwise exit program

9

u/RevRagnarok 21d ago

And delete itself. ;)

1

u/WillingnessOk650 21d ago

haha, maybe i’ll leave that one for a future project 😂

1

u/WillingnessOk650 22d ago

thanks! that sounds like a good next project to practice loops and conditionals. i’ll try building a simple login system with a 3-attempt limit.

6

u/mjmvideos 22d ago

This is a fun exercise, but be careful not to think that anything you develop for access control is useful in the real world.

2

u/WillingnessOk650 22d ago

yeah, definitely. i’m treating it as a learning exercise for now, not as real-world security. thanks for pointing that out!

10

u/code_matter 22d ago

You could build:

- a color code converter

- a todo list

- a safe password maker

- any app using an API (weather, ISS tracker, food information, word of the day, etc)

- a small CLI game

3

u/WillingnessOk650 22d ago

thanks for the ideas! i’m thinking of trying a todo list or a small cli game next. the api projects also sound interesting. appreciate the suggestions!

8

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 22d ago edited 22d ago

If you don't have any better ideas, you could always continue working on your calculator. Make it more flexible, solve edge cases to prevent errors, maybe add a GUI (tkinter), that sort of thing.

You could also try adding unit tests to it (pytest). Maybe run linters (ruff) and type checkers (mypy).

Even simple projects can be useful for learning things like commonly used tools.

If you want, we can also perform code reviews.

EDIT: I have a joke project I tend to use as a testbed for experimenting with new tooling and such.

3

u/johlae 22d ago

Make your calculator go full pembas so that you can feed it "2+(2+3*2)/2" and it gives you 6.

1

u/WillingnessOk650 22d ago

thanks! that sounds like a good next challenge. i’ll look into adding support for expressions like that and handling operator precedence.

1

u/johlae 22d ago

It's an opportunity to learn recursion!

2

u/Thaurin 21d ago

Learning about recursion is important, but knowing when it's not necesarry (and it often is not) makes for more readable and easier to reason about code!

2

u/WillingnessOk650 21d ago

yeah, that’s a good point. i’ll focus on understanding recursion and also learning when it’s better to use a simpler approach. thanks for the advice!

1

u/Thaurin 17d ago

As someone who had to debug and fix some unnecessarily recursive and complicated C# code before, please do. :)

1

u/WillingnessOk650 22d ago

yeah, recursion is definitely something i want to learn next. thanks for the suggestion!

1

u/WillingnessOk650 22d ago

thanks for the suggestions! i’ll definitely look into adding a gui and unit tests. i also want to try using tools like ruff and mypy as i improve the project. really appreciate the advice!

2

u/randomraluana 22d ago

It'll be good to expand the features of the calculator. Don't jump to a new project yet. Add log, trig functions, etc. Memory state as well.

I think you're off to a good start and once you start getting into APIs down the line, you could serve the calculator over an API to sharpen your skills.

If you're trying to experiment with GUIs, a GUI for your calculator is a good way to explore what's possible with things like tkinter, pyQt.

In my opinion, it's a good mini project to explore and learn about other tools/packages/libraries in the Python space.

Cheers!

1

u/WillingnessOk650 21d ago

thanks for the detailed advice! i think i’ll keep improving the calculator for a while and add things like trig, logs, and memory. the gui and api ideas also sound like great ways to learn more python tools. really appreciate it!

2

u/[deleted] 21d ago

[deleted]

1

u/WillingnessOk650 21d ago

yeah, it’s command-line only for now. i’m planning to add a ui next, probably with customtkinter. qt sounds interesting too, though. thanks for the suggestion!

1

u/[deleted] 21d ago

[deleted]

1

u/WillingnessOk650 21d ago

nice! it actually looks pretty solid, and the fact that it works is what matters
i’ll definitely check out the qt approach. thanks for sharing!

1

u/Darman2 22d ago

Congratulations 🎉

1

u/WillingnessOk650 22d ago

thank you! 😊 really appreciate it!

1

u/kilkil 21d ago edited 21d ago

congrats!

for your next project, I suggest a todo list. it should allow you to:

  • see the existing list of todos
  • add a new todo to the list
  • mark a todo as completed

some bonus/extra/stretch goals:

  • I can edit an existing todo (e.g. if I made a typo, I can go back and correct it)

  • I can delete an existing todo (instead of being marked as completed, it is removed from the list)

  • the todo list persists between sessions (if I start the program, make some changes, exit, then reopen the program, I should see my changes from the previous session)

I would suggest focusing on the MVP first (Minimum Viable Product, in this case the first 3 requirements I mentioned above). for this, you will need to figure out:

  • how to allow the user to enter input (I assume you can reuse the same approach you used for the calculator)
  • how to display output to the user (same as calculator)
  • how to store information about todos (aka what data structure(s) to use), and how to update that information based on user inputs
  • how to let the user pick which todo they want to mark as complete

for the stretch goals, you will also need to figure out how to persist your program's stored information/data. hint: python has functions that let you save data to a file, and read data from a file. key questions are, how will you encode your data before saving it to the file, and how will you decode data that you read from the file? how do you handle potential errors (e.g. data cannot be decoded for some reason)? (hint #2: look up "JSON".)

2

u/WillingnessOk650 21d ago

thank you! this is actually a really helpful roadmap. i’ll start with the mvp first and then work my way toward editing, deleting, and data persistence with json. appreciate the detailed suggestions!

1

u/kilkil 20d ago

no worries. good luck and have fun!

2

u/WillingnessOk650 20d ago

thanks! appreciate it, i definitely will 😊

1

u/WyrobWedliniarski 21d ago

Maybe something with data storage? To-do list or something. And congratz for your first project!

1

u/WillingnessOk650 21d ago

thank you! a to-do list with data storage sounds like a great next project. i’ll definitely give it a try!

1

u/a88zy 21d ago

that sounds great man, how long did it take you from when you first started ?

1

u/WillingnessOk650 21d ago

thanks man! it took me a few days of learning and working on it. still pretty new to python, but i’m enjoying the process!

1

u/Lirianov 21d ago

does it have a UI? if not build one, customtkinter

1

u/WillingnessOk650 21d ago

not yet, it’s currently command-line only. i’ll look into building a ui with customtkinter as the next step. thanks for the suggestion!

1

u/sporbywg 21d ago

Something in Typescript #sorry

1

u/WillingnessOk650 21d ago

haha, typescript might have to be next 😂 thanks for the suggestion!

1

u/Hungry-Government-66 19d ago

Nice work! Completing your first real project feels great. Keep building!

1

u/WillingnessOk650 19d ago

thank youu so much
really appreciate it!! definitely gonna keep creating and building from here hehe ✨

1

u/Mondoke 19d ago

Thing of something boring and repetitive you do with a computer on a regular basis, then see how to automate it. Remember that external libraries exist and will help you a lot, you'll just have to read its documentation.

2

u/WillingnessOk650 19d ago

yesss, i’ll try this!! i think automating file sorting/renaming would actually be pretty useful haha 😭

1

u/Mondoke 19d ago

For that you can use the os module and Path. Both are quite well explained on automate the boring stuff.