134k views
7 votes
You are designing a simple calculator program for young children to use. Right now, if they do something that the program didn’t expect, a message appears that reads, “User input deemed invalid.” What changes could you make so that the message would be more suitable for this audience?

User HiFI
by
3.9k points

1 Answer

13 votes

In Python, you can use a try-except statement and raise an exception with a custom message.

For example:

try:

x = int(input())

except:

raise Exception("User input deemed invalid")

In JavaScript, you can try using a try-catch statement. You can use the 'throw' keyword to handle the error.

User Yogesh Jog
by
4.4k points