Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

junglebooboo

  • 2 years ago

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

  • This Question is Closed
  1. FabienToune
    • 2 years ago
    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...

  2. FabienToune
    • 2 years ago
    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...

  3. junglebooboo
    • 2 years ago
    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

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

    Sure, much better like this !

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

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.