I have a very basic assignment, but I just simply can not get the right error I am looking for. Here is the assignment:
10-6 Addition: One common problem when prompting for numerical input occurs when people provide text instead of numbers. When you try to convert the input to an int, you'll get a TypeError. Write a program that that prompts for two numbers. Add them together and print the result. Catch the TypeError if either input value is not a number, and print a friendly error message. Test your program by entering two numbers and then by entering some text instead of a number.
Here is what I have:
print("Please enter two numbers and this program will add them together!")
try:
num_1 = int(input("What is your first number?"))
num_2 = int(input("What is your second number?"))
answer = num_1 + num_2
print(str(num_1) + " + " + str(num_2) + " = " + str(answer))
except TypeError:
print("Please make sure you enter a number next time.")
I have rearranged this for like an hour now, and no matter what I do I can't get a TypeError, only a ValueError. How am I able to get a TypeError in this, or is the book just wrong and it is impossible to get a TypeError in this scenario??
ValueErrorif I am not mistaken.