Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

junglebooboo

What is wrong with my python code? Mooc 6.189 user_input = int(raw_input('enter integer here: ')) print ' you entered the value', user_input while abs(user_input) > 0: abs(user_input) = abs(user_input) - 1

  • one year ago
  • one year ago

  • This Question is Closed
  1. FabienToune
    Best Response
    You've already chosen the best response.
    Medals 1

    You cannot attribute value to an expression... ie : abs(user_input) is invalid. If you want to take care of negative values, you should probably do something like user_input = abs(user_input) before the loop...

    • one year ago
  2. FabienToune
    Best Response
    You've already chosen the best response.
    Medals 1

    btw, you could just modify abs(user_input) = abs(user_input) - 1 by user_input = abs(use_input) - 1 but after the first iteration, all abs() operation would be useless, as the number would have been converted to positive at first loop...

    • one year ago
  3. junglebooboo
    Best Response
    You've already chosen the best response.
    Medals 0

    So this is a better code? user_input = int(raw_input('enter integer here: ')) print ' you entered the value', user_input while abs(user_input) > 0: if user_input < 0: user_input = user_input + 1 print user_input else: user_input = user_input - 1 print user_input

    • one year ago
  4. FabienToune
    Best Response
    You've already chosen the best response.
    Medals 1

    Sure, much better like this !

    • one year ago
    • Attachments:

See more questions >>>

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.