first we take input of some boolean logic like 2==2,if true then print("right") ,else print("wrong").I am not getting it,plzhelp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

first we take input of some boolean logic like 2==2,if true then print("right") ,else print("wrong").I am not getting it,plzhelp

input() if true: print("Right") else: print("Wrong")

22nd Jan 2017, 5:19 AM
shishir
3 Answers
+ 2
well if the condition is true and in the code it is, it will print right otherwise(if its false) will print wrong
22nd Jan 2017, 5:26 AM
Kawaii
Kawaii - avatar
+ 2
I'm not sure what the context is for your question but it sounds like you may be reading too much into some example code - the code may well be rather pointless code that just shows what the expression does (and not an actual practical usage) In this code: if true: print("Right") else: print("Wrong") since the condition (always the bit between the word if and the colon) is just "true" it will always do just print right, so in a way it is pointless code - but it is showing an example of an if statement and, if you run that code, you would see that it prints Right and not Wrong and this shows how the code converts to what the computer does in case it's not clear from the spacing and order of the code. A better example of what they are probably trying to teach in that example would be: myVariable = input () if myVariable == "hello": print("you typed in hello") else: print("you did not type in hello") Since it is slightly more feasible that you'd want a particular response for a set input this code shows the point of it as well as how to do it.
26th Jan 2017, 2:29 AM
Phil
Phil - avatar
- 3
This code will not work! It will always print Right! , and True False starting with capital letter.
22nd Jan 2017, 2:26 PM
Leshark
Leshark - avatar