- 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))
11 odpowiedzi
+ 1
The top says "double abs dif." So you need an absolute value there too.
+ 1
Ad long as n is greater than 17 then n-17 is always positive, so using absolute values is redundant.
+ 1
Your description says nothing about what is supposed to happen if n is not greater than 17.
+ 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.
0
How is anyone supposed to tell without any information about what you're trying to do? We're not mind-readers.
0
I have no idea what I'm doing. The top is explained
The bottom determines whith num is within 1000 or 2000
0
100 of 1000 2000
0
Yeah. It runs without it idk why
0
Return double abs val
0
This is off another teaching platform
0
Got it thank you