r/pythonhelp • u/jamesfarted09 • Dec 03 '20
Python Syntax Errors
Hi!
I was practicing some pretty easy scripts and all it does is see what a number is and print 'big' or 'small'. so can anyone tell me what the problem is?
x = 5
if x = 5 :
print('big')
if x = 1 :
print('small')
print('done!')
Also im using Pyscripter as an IDE
2
Upvotes
1
u/Tomboyish44 Dec 04 '20 edited Dec 04 '20
Hey, this code might give you the output that you're looking for:
Input:
Output:
The difference in assignment operators and equality operators:
I think in the code where you wrote
if x = 5 :, I think you intended to check if x is equal to 5, whenever we try to check if something is equal to something else, we use==in place of=. Why? Because we use=to assign values, not to check for equality.Here
=is an assignment operator, and==is an equality operator.Indentation:
bigis supposed to be printed if x is equal to 5, for that it needs to be in the same block of code as theif statementis.It can either be like this:
or this:
Since the block of code where the print statement has been written is in a new line, we indent it (There's one whitespace, there can be more too). If not indented, you'll get an indentation error.
Also, you can use PyCharm as your text editor if you want to, it's useful to use if you're new to Python, there are other cool editors too, just a suggestion.