Python questions (abs) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python questions (abs)

Solution is listed as 3. Any idea why this isn't 17 (equation below)? "What is the output of this code? j=10 jj=4 i=3+4 j=4 If j>abs(i): print (i+j) else: print(abs(i-jj))" -abs is absolute (highest integer). -j is 10 which is > than any other number (4, 3+4, or 4. -So why is the solution given as 3 and not 17 (i+j)? -Thanks for any help:).

18th Mar 2019, 10:35 PM
tristach605
tristach605 - avatar
4 Answers
+ 5
It's giving 17 as output. Try re-checking the answer.
19th Mar 2019, 12:25 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 3
tristach605 j got updated before if condition and it's holding 4 now which is less than i= 7.. so else condition is gonna executed... 7-4 = 3 is correct answer
19th Mar 2019, 3:10 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Thanks Shashi and Ketan👍🏻
19th Mar 2019, 7:01 AM
tristach605
tristach605 - avatar
0
I made a mistake in the origibal post. Have now edited it. Any help appreciates.
19th Mar 2019, 2:23 AM
tristach605
tristach605 - avatar