4 ms·
Wouldn't the correct answer be 5? result = result + x // 5 0 5
by forgotmypw17 10mo ago
Wouldn't the correct answer be 5?
result = result + x
// 5 0 5
- Daneel_ 10mo agoThe logic results in 3 + 3 - 5 = 1, so it's not 5, sorry. I'd love to know what logic path you followed to get 5 though!
- commandlinefan 10mo agoI did it in my head but got 4 (3 * 3 - 5), so I fail, too. Hopefully I'd be paying closer attention if I was actually applying for a job.
- spike021 10mo agowhere did your multiplication come from?
- commandlinefan 10mo agoFrom not paying close attention :)
- krackers 10mo agoPresumably you'd get it if you short-circuited and didn't evaluate the else part.
- kevin061 10mo ago3 comes before. Read it again.
- dinkleberg 10mo agoIt’s in a loop
- AlotOfReading 10mo agoIteration starts from the first element. X is 3, 3, then 5.
- forgotmypw17 10mo agoThanks to everyone who replied. I failed to account for the else condition when x is not > 3.