Try and except

I am reading [Python Crash Course] and doing ‘Try It Yourself’ exercises. What I am currently working on is “try and except”.

I am using sublime text 3 and after hitting “crtl + b” the console produces "input first number ". But nothing happens after type some number. what is happening?

first_number = input("input first number ")
second_number = input("input second number ")

    addition = first_number + second_number
except ValueError:
    print("please put numbers")

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Nothing happens is vague. You don’t get to second prompt? There is no output? There is an exception? Maybe show a screenshot?

prompt message is produced, I type some number. Then nothing happens.

Did you press enter to submit your input to the prompt?

yes. then the number I put in moves to the next line just like in text file. or the cursor moves to the next line just like in text file.

Can you show a screenshot of this? I find it really difficult to pinpoint your problem.

I think the problem is with Sublime Text 3. You can google “sublime text 3 input()”.

what if you run the script from the command line using the python interpeter? Do you run the correct python version?

it produces first and second prompt alright. But after I input numbers nothing happens. Below line appears again.
C:\Users\hp\AppData\Roaming\Sublime Text 3\Packages\User>

that is the expected behavior? What did you expect to see then?

1 Like

I coded wrong. I should have put int() for first_number and second_number. And print out Addition.
Were you anticipating this answer?

and the inputs should have been in the try block, in case you enter something other then a number/integer.

yes, I was :slight_smile:

Yes, next time I will pay attention to put them in the try block.