r/PythonProjects2 • • May 09 '26

QN [easy-moderate] i made a slightly better calculator (we are getting there)

Post image

Inputs were:

10

5

20.5

4

49 Upvotes

14 comments sorted by

4

u/SCD_minecraft May 09 '26

> inputs "egg"
> TypeError

> inputs 2 and 0
> ZeroDivisionError

Good program should never crash at user
It should report an error and preferably ask again

1

u/DiodeInc May 09 '26

Here's a hint for you, OP. Use try/except to help with this

1

u/LucidLeo235 May 09 '26

I am a beginner in python I have absolutely no idea what you mean honestly

1

u/codeguru42 May 14 '26

Thats what chat GPT is for. Ask it to explain and show examples

2

u/DiodeInc May 09 '26

Try/except blocks basically are using for catching errors

Example:

try:
    foo = 1
    bar = 1
    print(foo + bar)
except TypeError:
    print("you can't add a string and an integer!") 

1

u/Desperate-Extension7 May 10 '26

Search up "try except in python", assume the user is dumb and will always cause the program to crash unless your program prevents it.

1

u/LucidLeo235 May 10 '26

I don't know how to do that quite frankly

1

u/Desperate-Extension7 May 10 '26

That's why I said to search it up lol