-
Notifications
You must be signed in to change notification settings - Fork 177
Open
Description
Since the program on page 151 is like so:
try:
x = int(input('Enter the first number: '))
y = int(input('Enter the second number: '))
print(x / y)
except ZeroDivisionError:
print("The second number can't be zero!")
we will not get the :
TypeError: unsupported operand type(s) for /: 'int' and 'str'
if we give a "hello world!" as a 2nd number. Instead we will get that the typed input cannot be converted to int.
ValueError: invalid literal for int() with base 10: '"hello world!"
So the code on page 155 should be
try:
x = int(input('Enter the first number: '))
y = int(input('Enter the second number: '))
print(x / y)
except ZeroDivisionError:
print("The second number can't be zero!")
except ValueError:
print("Are you sure you typed an integer?")
Metadata
Metadata
Assignees
Labels
No labels