What is the output of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the output of this code?

x = 8 x /= 2 y = 1 x.times {y+=2} puts y

10th Jan 2018, 9:24 AM
h a w k
8 Answers
+ 23
9
10th Jan 2018, 9:26 AM
Nithiwat
Nithiwat - avatar
+ 2
I figure it out. thanks
10th Jan 2018, 9:32 AM
h a w k
+ 2
๐Ÿ”ดFinal Answer 3/3๐Ÿ”ต but first read process x=8 x/=2 y=1 x.times{y+=2} puts y ................................... I understand this: x=4 4.times{1+2} puts y Correct Output Answer 9
23rd Jan 2018, 7:32 PM
Nestor Velez
Nestor Velez - avatar
+ 2
i think ans is 9
14th Mar 2018, 4:00 AM
Alexey Belousov
Alexey Belousov - avatar
+ 1
First the variable x is divided by 2, giving us a result of 2, then we put to variable y with 1. Finally we make a loop with 4 iterations, (4*2) + 1 from y = 9
14th Mar 2018, 4:59 PM
David Rueda ๐Ÿ‡ช๐Ÿ‡ธ
David Rueda  ๐Ÿ‡ช๐Ÿ‡ธ - avatar
+ 1
9
30th Mar 2018, 6:17 AM
amrendra singh rathore
amrendra singh rathore - avatar
0
Hi. X =8 X=4 Y=1 4 times 1+=2 4*2+1=9 Final result is 9
28th Mar 2018, 2:13 PM
David Rueda ๐Ÿ‡ช๐Ÿ‡ธ
David Rueda  ๐Ÿ‡ช๐Ÿ‡ธ - avatar
0
I am sorry but i donโ€™t understand why the output is 9. To me it would be 12. I get all the variable right but why do we 4 times 1+=2 to 4*2+1? ๐Ÿคทโ€โ™‚๏ธ
4th Oct 2020, 2:22 PM
Timothy Cohen
Timothy Cohen - avatar