+ 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")
3 Respostas
+ 2
well if the condition is true and in the code it is, it will print right otherwise(if its false) will print wrong
+ 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.
- 3
This code will not work!
It will always print Right! , and True False starting with capital letter.