Issue
I'm running some basic commands in Jupyter Notebook(via python 3), and my they aren't running properly. In the code if I set A to equal 1, the IF statement works fine but if I set it higher than b the else statement doesn't do anything. it simply prints test without the else string i wrote. I'm very new to coding, so I apologize for any incorrect terminology. I used proper spacing for the if-else statements as well(4 spaces) Here is my code.
edit: I did find an alternative code that functions properly but I'm still confused as to why the first doesn't work, here is the alternative.
edit 2: it has come to my attention that I should have posted the code in text, so Ill post the first one(the problem):
a = 5
b = 2
if a < b:
print("a is less than b")
else:
print:("a is NOT less than b")
print ("test")
Solution
Your issue is you have a colon after your print word in the else statment. change
print:("a is NOT less than b")
to
print("a is NOT less than b")
Answered By - Chris Doyle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.