What should it print ? | Sololearn: Learn to code for FREE!

+4

What should it print ?

what should it print when the code is print 5*4+3/2-1; in the language of ongoing coding contest "Custom Interpreter" For rules see this https://www.sololearn.com/learn/9298/?ref=app

6/11/2018 1:56:10 AM

Vishal Pal❄️⚛️

7 Answers

New Answer

+5

The requirements specifications did not touch on operator precedence, but I believe it would be a delighter for your interpreter to be able to calculate the statement according to proper norms, 5*4+3/2-1 (5*4)+(3/2)-1 From the syntax, the fictional language appears to be dynamically-typed. I'm assuming that the division between two integer values would result in an integer result, while the case where either or both parameters are floating-point values, would result in a floating-point value result. (5*4)+(3/2)-1 20+1-1 20 Of course, both of the above appears to be beyond the scope of this assignment.

+4

If I were to judge, both are acceptable. 20.5 is obtained by carrying out floating-point operation when given two integer values as operands. This isn't wrong. Python, for instance, does that. While 10 is a bit unorthodox, we were not told/required to develop a language with operator precedence, and hence should not be disqualified as well.

+4

Thanks Hatsy Rei

+4

I'd say it's (5*4)+(3/2)-1 20+(3/2)-1 20+1.5-1 21.5-1 20.5 Makes more sense to me to make every number a float because the language doesn't offer explicit type casting.

+3

Hatsy Rei what if interpreter is showing 20.5 or 10?

+3

5*4+3/2-1 = (5*4)+(3/2)-1 = 20+1-1 =20. Note that 3/2 = 1, but 3.0/2.0=1.5

0