Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Sure, much better like this !

Not the answer you are looking for?

Search for more explanations.

Ask your own question