0
A bug in python code
What is wrong with this code? House rent payment=250000 So I If I run this code It would say invalid syntax how can I debug this?
3 Antworten
+ 3
Folakemi In Python, there are rules where you cannot use special characters (i.e: *, ", ', :, ...) AND spaces to name your variable. A variable name also must NOT start with a number.
To fix this, you can replace space with underscores (_):
House_rent_payment=250000
In Python, it is recommended to use all lowercase letters to name a variable in most cases.
house_rent_payment=250000
(You can shorten the name of the variable. Like: rent_payment=250000
Optional, but keeping variable names short may increase the readability of your code)
Lastly, optional but highly recommended: Add spaces around the operator for readability.
house_rent_payment = 250000
0
The syntax error is in the variable name. Variable names may not have spaces in the name. As a workaround, programmers typically use the underscore character, "_", where they would want to have a space.
Try naming your variable like this:
House_rent_payment=250000
Also it is conventional to use all lowercase letters for simple integer variables like in this case. Further, I would add spaces around the assignment operator for readability. So this would be more like the convention:
house_rent_payment = 250000
0
For more information about python coding style guide (for readability), see PEP 8 https://peps.python.org/pep-0008/ .
Always make your code readable. Everyone may not see your code, but you will.