if 1 + 1 * 3 == 6 print ("Yes") else : print ("No") | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

if 1 + 1 * 3 == 6 print ("Yes") else : print ("No")

Im getting invalid output

16th Apr 2018, 4:53 PM
Elisha Miracle
Elisha Miracle - avatar
24 Answers
+ 6
Normally, the operator precedence is this: parenthesis, multiplication, division, modulus, addition and subtraction 1 + 1 * 3 = 4 1 + ( 1 * 3 ) = 4 ( 1 + 1 ) * 3 = 6
16th Apr 2018, 4:58 PM
voidneo
+ 4
That's an invalid syntax. You're missing a colon (:) after 6.
16th Apr 2018, 4:55 PM
Dev
Dev - avatar
+ 2
like that?
16th Apr 2018, 5:15 PM
Elisha Miracle
Elisha Miracle - avatar
+ 1
I get it now
16th Apr 2018, 5:23 PM
Elisha Miracle
Elisha Miracle - avatar
+ 1
thanks y'all
16th Apr 2018, 5:24 PM
Elisha Miracle
Elisha Miracle - avatar
+ 1
Just check the precedent at first. Parantheses >exponentiation > multiplication/division > addition/ subtraction. It's shown the value is not true, so extract to No
24th Oct 2020, 7:54 PM
aryan shahrabi
0
okay
16th Apr 2018, 4:56 PM
Elisha Miracle
Elisha Miracle - avatar
0
it's still the same
16th Apr 2018, 5:07 PM
Elisha Miracle
Elisha Miracle - avatar
0
if (1+1*3==6) { print ("yes") ; } else : { print ("no") ; }
16th Apr 2018, 5:07 PM
Elisha Miracle
Elisha Miracle - avatar
0
still error
16th Apr 2018, 5:07 PM
Elisha Miracle
Elisha Miracle - avatar
0
As Dev said, you're missing a colon, it should be like this: if ( 1 + 1 ) * 3 == 6: // do stuff
16th Apr 2018, 5:10 PM
voidneo
0
like this one??
16th Apr 2018, 5:15 PM
Elisha Miracle
Elisha Miracle - avatar
0
multiplication is executed first .... in order to add 1 to 1 first , and then multiple the result by 3 u must put the addition in ()
16th Apr 2018, 5:20 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
if( (1+1) * 3 ==6) { bla bla bla }
16th Apr 2018, 5:21 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
Expanding on what noname said. Here's an article on Operator Precedence: https://en.wikipedia.org/wiki/Order_of_operations
16th Apr 2018, 5:55 PM
Emma
0
No, multiplication, add, equal
8th Sep 2019, 2:15 PM
sasmita dash
sasmita dash - avatar
0
Because the first it is multipluing
25th Dec 2019, 12:49 PM
Денис Конушум
0
Elisha Miracle if 1 + 1 * 3 == 6 : print ("Yes") else : print ("No")
6th Jan 2022, 10:05 AM
𝑺𝑯𝑼𝑩𝑯𝑨𝑴 𝑹𝑨𝑱
𝑺𝑯𝑼𝑩𝑯𝑨𝑴 𝑹𝑨𝑱 - avatar
0
What is the result of this code? if 1 + 1 * 3 == 6: print("Yes") else: print("No")
29th Nov 2022, 7:46 AM
Thinley Choden
Thinley Choden - avatar
0
What is the result of this code? if 1 + 1 * 3 == 6: print("Yes") else: print("No")
29th Nov 2022, 7:46 AM
Thinley Choden
Thinley Choden - avatar