Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page 154 chapter 8 #12

Open
georgiosdoumas opened this issue Apr 27, 2019 · 0 comments
Open

page 154 chapter 8 #12

georgiosdoumas opened this issue Apr 27, 2019 · 0 comments

Comments

@georgiosdoumas
Copy link

georgiosdoumas commented Apr 27, 2019

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?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant