我该如何解决这个问题并正确评估它 [英] How do I do this problem and evaluate it correctly
问题描述
评估以下表达式:
4 + 3 * 80 +你好+ 4 * 9 + 45/2
回答是:
我以为这只是你好
我尝试过的事情:
不知道怎么做!
i尝试了你好和数字,但没有工作
Evaluate the following expression:
4+3*80+"Hello" +4*9+45/2
The answer is :
I thought it would be just Hello
What I have tried:
No clue how to do this!
i tried hello and the number but that didnt work
推荐答案
把你的表达式放在print语句中,看看会发生什么,你会发现这个回答
Put you expression in the print statement and see what happens, you will find this answer
244Hello3622
我们如何得到这个答案?
数学中有一个名为 BODMAS 的规则,代表分区,乘法,加法和减法的括号
好吧我们将你的表情分成两个
How we get this answer?
There is a rule in mathematics named BODMAS which stands for Brackets of Division, Multiplication, Addition and Subtraction
ok we will split up your expression into two
exp1: 4+3*80 exp2: 4*9+45/2
解决exp1:
在BODMAS M之前是A,所以我们必须先增加
80 * 3 = 240
240 + 4 = 244
所以exp1的结果是244
解决exp2:
分区第一,乘法第二和加法分数
45/2 = 22.5(约22)
4 * 9 = 36
我们不再解析表达式2
表达式1的结果是244后跟+Hello,它不是加法运算符而是连接运算符所以244Hello是字符串,并且没有添加其他东西但是连接244Hello+(4 * 8)给出244Hello36,最后是244Hello3622
Resolving exp1:
In BODMAS M comes before A so we have to multiply first
80*3 = 240
240+4 = 244
so the result of exp1 is 244
Resolving exp2:
Division comes first, Multiplication second and Addition thid
45/2 = 22.5 (22 approx)
4*9 = 36
we dont resolve the expression 2 further
the result of expression1 is 244 is followed by + "Hello" which is not an addition operator but a concatenation operator so "244Hello" is string and further things are not added but concatenated "244Hello"+(4*8) gives "244Hello36" and finally "244Hello3622"
这篇关于我该如何解决这个问题并正确评估它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!