Hi guys, Shahanaz here again! As a first-year CSE student at PACE Mangalore, these are the exact syntax rules that saved my code from crashing during my lab assignments this week.
What is a Float?
• Float means a decimal number, like 72.5, 98.0, or 3.14.
• Int means a whole number, like 18 or 5.
• Rule: Always use float(input) instead of int(input) whenever your user might type a decimal value, like college marks or percentages.The Python Bracket Map
• Parentheses ( ) are used to run functions. For example: print("Hello") or input().
• Curly Brackets { } are used inside f-strings to print out your calculated math variables. For example: f"Total: {total}".When to use a Colon :
Think of the colon as a gateway. It tells Python that a brand new set of instructions is starting right below it. You must always put a colon at the very end of your if, elif, and else lines.Code Alignment Rules
Python tracks your code logic using vertical spaces on the left margin.
• Your if, elif, and else statements must line up on the exact same vertical line.
• The action words like print must be pushed inward by 4 spaces or 1 tab.
If they do not line up perfectly, your code will fail with an IndentationError!
Top comments (0)