Skip to content

Commit

Permalink
Added function to remove leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
joseignaciostassi committed Nov 10, 2023
1 parent 27177d6 commit d364597
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def click_event(key, event=None):
# Safeguard against integer division
if '/' in entry.get() and '.' not in entry.get():
entry.insert(tk.END, ".0")


# Remove leading zeros
expression = entry.get().lstrip('0')

# Attempt to evaluate results
try:
result = eval(entry.get())
result = eval(expression)
entry.delete(0, tk.END)
entry.insert(tk.END, str(result))
except:
Expand Down

0 comments on commit d364597

Please sign in to comment.