Jun 11, 2012 at 8:36pm UTC
sum = 0
num = 10
if (num > 5)
sum = sum + 10;
else
if (num = 10)
sum = num = 15;
sum = sum + num
answers:
a= 0
b= 20
c= 10
d= 25
I gave "C" (10) as an answer, but i was wrong.. can you tell me what the answer is and why ? thanks
Jun 11, 2012 at 8:40pm UTC
Look more carefully at the if statements. This is why indentation is important to making code easy to understand.
Jun 11, 2012 at 9:05pm UTC
I think I got it... the "if" is True, so the first statement applies...meaning sum=10, then "else" is by passed, and then sum = 10 +10
that is .. sum=20 right ?
Jun 11, 2012 at 10:15pm UTC
That's the answer I came up with.
Jun 12, 2012 at 1:27am UTC
20 is correct. You could always compile and run the code as well :p (provided you aren't still in the middle of the test)
Jun 12, 2012 at 2:01am UTC
Thanks guys for your help...and no...I wasn't in the middle of a test :O)