A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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))

  • This Question is Closed
  1. nowhereman
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. nowhereman
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    As long as you don't input anything which can be converted to an integer, you will get an error.

  4. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.