Skip to content

page 154 chapter 8  #12

@georgiosdoumas

Description

@georgiosdoumas

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions