Confused with my code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Confused with my code

I have the following code written for an "if" statement if True: x = "hello" print(x) else: y = "goodbye" print(y) Whatever I enter in after the "y" statement I get a result of hello or true. Even after entering 2 != 2 I get true. Could someone explain why thing is to me? I feel as if this is because of how I have the code written, if anyone could help I would appreciate it.

8th Nov 2016, 3:28 AM
Shawn Bellmore
Shawn Bellmore - avatar
4 Answers
+ 1
if condition: statements else: statements If the condition is True then if statements will execute otherwise else statements will execute In your case the condition is always true so if will execute Just make the condition to False or 0 then else would execute
8th Nov 2016, 3:45 AM
рооройрпЛроЬрпНроХрпБрооро╛ро░рпН рокро┤ройро┐роЪрпНроЪро╛рооро┐
рооройрпЛроЬрпНроХрпБрооро╛ро░рпН рокро┤ройро┐роЪрпНроЪро╛рооро┐ - avatar
+ 1
You missed a simple thing. True is not a condition. it is a answer of condition. if statement will execute if the result of condition is true. so it executes as you defined it already. use conditional instead.
8th Nov 2016, 4:24 AM
Iqbal Mohammad Rhidwan
Iqbal Mohammad Rhidwan - avatar
8th Nov 2016, 4:31 AM
рооройрпЛроЬрпНроХрпБрооро╛ро░рпН рокро┤ройро┐роЪрпНроЪро╛рооро┐
рооройрпЛроЬрпНроХрпБрооро╛ро░рпН рокро┤ройро┐роЪрпНроЪро╛рооро┐ - avatar
0
@manoj. is there any way to use python instead of php in developing website without framework.?
8th Nov 2016, 4:27 AM
Iqbal Mohammad Rhidwan
Iqbal Mohammad Rhidwan - avatar