Why does one require an absolute value but not the other | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Why does one require an absolute value but not the other

#if number is greater then 17 double abs dif. def difference(n): if n <= 17: return 17 - n else: return (n - 17) * 2 print(difference(22)) print(difference(14)) def near_thousand(n): return ((abs(1000 - n) <= 100) or (abs(2000 - n) <= 100)) print(near_thousand(1000)) print(near_thousand(900)) print(near_thousand(800)) print(near_thousand(2200))

12th Aug 2021, 10:10 PM
Aaron
Aaron - avatar
11 Answers
+ 1
The top says "double abs dif." So you need an absolute value there too.
12th Aug 2021, 11:25 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Ad long as n is greater than 17 then n-17 is always positive, so using absolute values is redundant.
12th Aug 2021, 11:28 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Your description says nothing about what is supposed to happen if n is not greater than 17.
12th Aug 2021, 11:29 PM
Simon Sauter
Simon Sauter - avatar
+ 1
The way you have defined the difference function it will always return a positive value, so there is no need for using absolute values.
13th Aug 2021, 12:03 AM
Simon Sauter
Simon Sauter - avatar
0
How is anyone supposed to tell without any information about what you're trying to do? We're not mind-readers.
12th Aug 2021, 11:18 PM
Simon Sauter
Simon Sauter - avatar
0
I have no idea what I'm doing. The top is explained The bottom determines whith num is within 1000 or 2000
12th Aug 2021, 11:21 PM
Aaron
Aaron - avatar
0
100 of 1000 2000
12th Aug 2021, 11:21 PM
Aaron
Aaron - avatar
0
Yeah. It runs without it idk why
12th Aug 2021, 11:25 PM
Aaron
Aaron - avatar
0
Return double abs val
12th Aug 2021, 11:54 PM
Aaron
Aaron - avatar
0
This is off another teaching platform
12th Aug 2021, 11:55 PM
Aaron
Aaron - avatar
0
Got it thank you
13th Aug 2021, 12:03 AM
Aaron
Aaron - avatar