r/PythonLearning • • Jul 16 '25

Help Request Could it be simpler ?

Post image

I'm totally new to programming in general not only in Python so as according to the advises I received, many people told me to code instead of watching tutorials only and so I did, I made this simple calculator with instructions of course but could it be easier and simpler than this ?

178 Upvotes

61 comments sorted by

View all comments

2

u/SCD_minecraft Jul 17 '25

I would ask for a mode, then for the numbers (do quick validation like 1/0 is not allowed) and maybe make those modes as a functions?

Let's say

modes = {
"add": lambda a, b: a+b, 
"sub": lambda a, b: a-b
}

print(modes[selected_mode](a, b))