Does anyone else get an error message when using this in idle? The example is giving in the reading assignment but it doesn't work and I'm not understanding why. I get the error message when I enter: plusTen = number + 10 print ("Please give me a number:",) response = raw_input() number = int(response) plusTen = number + 10 print ("If we add 10 to your number, we get " + str(plusTen))
Observe that there is a different syntax for print in python-2 and python-3. Also the user-input in your case must be a legal number. If you enter "plusTen = number + 10" that is not a number and an exception is thrown. You should catch that in the code.
i understand the "type" error. the reading says that to fix it you need to use 'int' and 'str'. the modified example in the reading gives me the error message, though, it does not work with the fixes it recommends.
As long as you don't input anything which can be converted to an integer, you will get an error.
It's a bit odd to be printing a tuple as a prompt before an input function call? For Python2, it'd be a little more sane to do: response = raw_input('Please give me a number: ') number = int(response) # will crash if this conversion isn't doable plusTen = number + 10 print 'If we add ten to your number, we get ' + str(plusTen) For Python3: response = input('Please give me a number: ') number = int(response) # can crash still plusTen = number + 10 print('If we add ten to your number, we get', plusTen) Dunno if that helps at all.
Join our real-time social learning platform and learn together with your friends!